Partiolaiset Kompassi is a progressive web app made mainly for mobile devices. This is the backend repository of the application. Main purpose of the app is to store and show scout members's completed achievement badges. Groupleaders are also able to give new achievement badges to their groupmembers. Users that are not logged in can view different tasks and their info.
This backend application and Postgre database are deployed to an Azure. This application is an Rest API for pos-frontend. It fetches userprofile data from Kuksa(rest-kehatieto), uses partio-id as a sign-in method and stores user's activity achievements data to pos-db.
You can start database by running docker-compose up
.
You can create needed tables by running yarn migrate-up
.
Install ngrok, it is preferred to use Homebrew brew cask install ngrok
.
Get content for ngrok-config from 1Password and place it to ~/.ngrok2/ngrok.yml
. Also edit your /etc/hosts
and add partio.ngrok.io
as a hostname for 127.0.0.1
Start ngrok with yarn ngrok
or alternatively ngrok start partio
.
Get a working .env file from 1Password.
No tests at the moment.
To start the dev env run yarn dev
.
NOTE: You will need to generate certificates for the localhost https environment. See the steps below.
To start the app in https mode
- run
yarn dev
(requires that you have the certificate files in thecerts
folder)
To generate the required certificate follow these steps (Mac):
NOTE 1: Make sure you have all the https related environment variables set (see .env.example).
NOTE 2: If you've already created and added the root key and root certificate during the frontend https setup you can skip step 1.
-
First create a folder (e.g.
certificates
) somewhere on your Mac- for example to your Work/Projects folder if you have them or your Desktop/Downloads folder
- If you created the folder in finder open a terminal and
cd
to the folder - Next run the following commands to create the required files for generating the certificates
- Create a root key:
openssl genrsa -des3 -out rootCA.key 2048
- Create RootCA.key pass phrase when terminal asks for it and save it somewhere (You're going to need it later)
- Create a root certificate:
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
- It's enough to only fill some fields here. E.g. Country as
fi
and location asHelsinki
- It's enough to only fill some fields here. E.g. Country as
- Create a root key:
- Next you need to add the created root certificate as trusted in your Keychain Access application
- Open Keychain Access
- Select
File
->Import items...
from the app menu - Navigate to the folder where you created
- Select System from the left side menu and then the Certificates tab
- Double-click the certificate you added and change its Trust setting to Always Trust
-
Create a separate folder for backend inside your certificates folder:
mkdir backend
-
Create a
server.csr.cnf
file inside thebackend
folder with the following information-
[req] default_bits = 2048 prompt = no default_md = sha256 distinguished_name = dn [dn] C=fi L=Helsinki CN = pos-api-dev.ngrok.io
-
-
Create a
v3.ext
file inside thebackend
folder with the following information-
authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = pos-api-dev.ngrok.io
-
-
Run
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat backend/server.csr.cnf )
-
Run
openssl x509 -req -in backend/server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile backend/v3.ext
-
Now the certificates are ready so all you need to do is move the
server.crt
andserver.key
files inside thebackend
folder to the backend project- Create a
certs
folder inside the backend project - Move the
server.crt
andserver.key
inside thecerts
folder
- Create a
-
-
Edit
~/.ngrok2/ngrok.yml
addr: 3001
should be changed toaddr: https://localhost:3001
-
Run ngrok with
yarn ngrok
-
Run
yarn dev
to start the app
When working on a new feature or fixing a bug always create a new branch from the master branch. When the feature or fix is complete create a pull request (from now on PR) for the branch. There should always be at least one or two reviewers for the PR and once the PR has been approved it can be merged to master.
TODO
Anything pushed to the master branch is automatically deployed to the test environment.
Make sure the GitHub action successfully completes and test environment is accessible and these things works:
- TODO
Tests - should there be any - are automatically run during the GitHub workflow when things are pushed to the master branch.
TODO
As everything from the master branch is deployed to the test environment the only way to change what is deployed is to push new changes or reverting old commits.
TODO
TODO
TODO.
Create a release in GitHub.
Make sure the GitHub action successfully completes and production environment is accessible and these things works:
- TODO
Tests - should there be any - are automatically run in the Github action flow.
TODO
Fix the release
TODO
TODO
Github Actions is used for CI.
- Go to azure portal https://portal.azure.com/#home
- Select the database of the environment you want to run migrations to (production or staging)
- Select "Connection security" from the left menu (under settings)
- Add your IP to the allowed IP lists by clicking the "+ Add current client IP address (you.rip.add.ress)" button and the click the save button at the top left of the view
- Next go back to the home screen and select the backend of the environment you want to run migrations to
- Select Configuration from the menu on the left (under settings)
- Copy the value of the DATABASE_URL
- Here you have two choices:
-
- In your local dev environment run the following command:
DATABASE_URL=paste-the-value-from-part-7-here yarn migrate-up
- In your local dev environment run the following command:
-
- Set the DATABASE_URL from part 7 to your local .env file and run:
yarn migrate-up
- Set the DATABASE_URL from part 7 to your local .env file and run:
-
- Remove your IP address from the list allowed IP addresses:
- Follow steps 1 to 3 of this guide
- Click the delete icon to the right of your IP address in the list of IPs
- Click save from the top left of the view