- Production Deployment
- Dev Deployment
- How to deploy a new version of the Lambda function
- How to set up a local server dev environment
- How to run the linter
- How to configure new Buttons
- How to check the logs
- How to add a PostgreSQL migration script
- How to access a remote database
- How to view which migration scripts have been run and when
- How to add or change an encrypted Github Actions environment variable
- How to run a migration script
- How to migrate data from one PostgreSQL database to another
- How to migrate passwords and API keys for offboarding
-
check the deployment ClickUp Task for any comments or SubTasks that could affect these deployment steps.
-
send a message to the
#buttons-aa-general
Slack channel letting everyone know that you are doing a deployment and to expect some downtime. -
on your local machine, in the
BraveButtons
repository:-
pull the latest code ready for release:
git checkout main && git pull origin main
-
decide on an appropriate version number for the new version
-
update CHANGELOG.md
-
Add a new section header with the new version number and the current date below the
[Unreleased]
link so it will look like this:[<new version number>] - YYYY-MM-DD
-
Create a new link for the new version near the bottom of the file that looks like this:
[<new version number>]: https://github.com/bravetechnologycoop/BraveButtons/compare/v<previous version number>...v<new version number
-
Update the
[unreleased]
link to[unreleased]: https://github.com/bravetechnologycoop/BraveButtons/compare/v<new version number>...HEAD
-
-
make a new commit directly on
main
which only updates the CHANGELOG -
tag the new commit - for example, if the version number is v1.0.0, use
git tag v1.0.0
-
push the new version to GitHub:
git push origin main --tags
-
update the
production
branch:git checkout production && git merge main && git push origin production
-
-
on the production Buttons server (access using ssh):
- update the values in
~/BraveButtons/server/.env
- update the values in
-
sign into the particle-accelerator
-
go to message clients and select "Buttons" as the product
-
send a downtime message to all the active clients letting them know that you are doing some routine maintenance, there will be downtime, and that you will notify them when everything is back to normal again.
-
on the production Buttons server (access using ssh):
-
cd into the
BraveButtons/server
directory -
shut down the server process and ensure that environment variables are not cached:
pm2 kill
-
pull the latest production code:
git checkout production && git pull origin production
-
run the server setup script:
sudo ./setup_server.sh ./.env
-
-
open the production dashboard and confirm that everything appears to be working normally
-
Verify that the logs look reasonable
-
on the production Buttons server (access using ssh):
- run
pm2 logs
- run
-
-
go back to the particle-accelerator and login
-
go to message clients and select "Buttons" as the product
-
send a uptime message to all the active clients letting them know that the routine maintenance is done and everything is back to normal again.
-
send a message to the
#buttons-aa-general
Slack channel letting everyone know that the deployment is finished and list the changes in this deployment from theCHANGELOG
-
update the ClickUp Tasks
-
if appropriate, send a Feature Change Announcement email to the clients
-
on the dev Buttons server (access using ssh):
- update the values in
~/BraveButtons/server/.env
- update the values in
-
on the dev Buttons server (access using ssh):
-
cd into the
BraveButtons/server
directory -
shut down the server process and ensure that environment variables are not cached:
pm2 kill
-
pull the latest code from your branch:
git checkout <your branch> && git pull origin <your branch>
-
run the server setup script:
sudo ./setup_server.sh ./.env
-
-
cd into the
lambda
directory -
run
./setup_lambda.sh
-
login to the AWS account for the envrionment where you want to deploy the version
-
navigate to Lambda --> Functions
-
click on 'lora-parse'
-
click on 'Upload from' --> .zip file
-
upload the newly generated file
lambda/buttons_lambda.zip
-
clone this repository
-
cd into the
server
directory -
run
sudo apt install postgresql
to install postgres -
in
/etc/postgresql/<VERSION>/main/pg_hba.conf
changelocal ... all ... all ... peer
tolocal ... all ... all ... md5
-
copy
.env.example
to.env
and fill out variables appropriately for your local environment -
run
source .env
-
run
sudo PG_PORT=$PG_PORT PG_USER=$PG_USER PG_PASSWORD=$PG_PASSWORD PG_HOST=$PG_HOST ./setup_postgresql_local_dev.sh
-
to check that everything is working, run
npm test
and check that the tests pass. -
to run the server locally and see the dashboard, run
npm start
and browse tolocalhost:8000
-
cd into the
server
directory or thepairing-tool
directory, depending on which you want to lint -
run
npm install
-
run
npm run lint
- See latest instructions here: https://app.clickup.com/2434616/v/dc/2a9hr-2261/2a9hr-7622
-
To view the logs on the server, first SSH into the server.
-
Run
pm2 logs
to follow a tail of both console and error logs -
Run
less ~/.pm2/logs/BraveServer-out.log
to view the console logs orless ~/.pm2/logs/BraveServer-error.log
to view the error logs -
Run
tail -f ~/.pm2/logs/BraveServer-out.log
to follow the tail of the console logs ortail -f ~/.pm2/logs/BraveServer-error.log
to follow the tail of the error logs -
Run
zcat ~/.pm2/logs/<filename.log.gz> | less
to view any of the archived logs in~/.pm2/logs
-
This strategy assumes that each migration script in the db
directory has a unique positive integer migration ID,
and that each script's migration ID is exactly one greater than the previous script's migration ID.
Otherwise, the scripts will not run.
-
Copy
db/000-template.sql
and name it with its migration ID (padded with zeros) followed by a short description of what it does -
Update the file with its migration ID and the new migration scripts
-
Add the call to the migration script to
setup_postgresql.sh
To access the remote database you'll first need to add the IP you're trying to access it form to the "trusted sources" section of the digital ocean database console located at https://cloud.digitalocean.com/databases/button-db
To connect, use the connection details available from the connection pools page on Digital Ocean - there should be a pool for testing and one for production, and connection details will be available as individual parameters, a connection string, and as a psql command with the necessary flags filled in https://cloud.digitalocean.com/databases/button-db/pools
PGPASSWORD=<password> psql -U <user> -h <hostname>.com -p <port> -d <database> --set=sslmode=require
You can also append the standard psql flags (like -c for commands or -f for file input)
SELECT *
FROM migrations
ORDER BY id;
Reference: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
-
Go to the GitHub repo in your web browser
-
Go to the settings page
-
Under the Security section, click on Secrets and variables, then click Actions
-
Under Repository secrets, click New repository secret or edit an existing one with the pen symbol
Run the setup_postgresql.sh script, making sure to provide the necessary environment variables before the command. The command needs values for PG_PASSWORD, PG_HOST, PG_USER, and PG_PORT, which will be available in the [connection details section of the managed database page on Digital Ocean.]https://cloud.digitalocean.com/databases/button-db)
PG_PASSWORD=password PG_USER=database PG_HOST=hostname PG_PORT=port ./setup_postgresql.sh
The standard way to migrate data is to use the pg_dump command to create a backup of the old database (which is just a sequence of PostgreSQL commands) and to feed this file to the new database.
If you're migrating from a local database to a remote database that has already had users created and migration scripts run on it, you'll want to create this backup without owners (using the -O flag) and specify to only dump the data, not the schema (with the --data-only flag).
You can either pipe the output of pg_dump directly to the new database
pg_dump --data-only -O pg_brave | PGPASSWORD=password psql -U db_user -h dbhost.com -p 12345 -d targetdatabase --set=sslmode=require
or save it to an intervening file, and then input this file to the database
pg_dump --data-only -O pg_brave > bravedata.sql
PGPASSWORD=password psql -U db_user -h dbhost.com -p 12345 -d targetdatabase --set=sslmode=require < bravedata.sql
When performing a migration, make sure to connect directly to the target database rather than through a connection pool.
In all of the following tutorials, please reset the 1password entries where they exist.
Make sure to turn off either the development or production environment as you are doing the password migrations, messaging clients before and after the downtime using PA.
The same Twilio token is used between the development and production buttons servers, so replace the environment variable in both servers.
- Go to the Twilio Console and log in.
- Select Button Project from the project drop down (top-left).
- Go to Acount Management from the Admin drop down (top-right).
- Go to API keys & tokens under Keys & Credentials (left).
- Scroll down to Live credentials and click Request a secondary token.
- There should be a prompt to use the secondary token as the primary token and remove the old one - click this.
- Set the
TWILIO_TOKEN
environment variable to the new primary token.
- Generate a new dashboard password with a password generator.
- Set the
PASSWORD
environment variable to the generated password.
In the following tutorial, the password for the braveprod user should be used for the production server. Likewise, the password for the bravetest user should be used for the development server.
- Go to DigitalOcean and log in.
- Go to Databases from the manage menu (left).
- Go to the button-db page from the list of databases (centre).
- Select the Users & Databases tab.
- Click on the three dots to the right of the braveprod user and click Reset Password.
- When reset, click on show next to the braveprod user and copy the password.
- Repeat the previous two steps for the bravetest user (development server).
- Set the
PG_PASSWORD
environment variable to the new user password per environment.
Note: there are different RAK API keys between the production and development servers.
Repeat the following steps for the dev bravedevices AWS dashboard as well as the aws-buttons-prod AWS dashboard.
- Log in to the AWS app dashboard, and select ButtonsAdministrators under bravedevices (prod first).
- Open the Lambda service.
- Select the lora-parse lambda function.
- Select the Configuration tab.
- Click on Edit next to the Environment variables menu (top-right).
- Generate a new RAK API key with a password generator.
- Change the value of RAK_API_KEY to the newly generated API key.
- Set the
RAK_API_KEY_PRIMARY
environment variable to the new API key for the respective env.
- Go to DigitalOcean and log in.
- Go to App Platform from the manage menu (left).
- Go to the particle-accelerator page from the list of apps (centre).
- Open the Settings tab.
- Open the particle-accelerator component.
- Scroll down to environment variables, and click Edit.
- Generate three new Brave API keys with a password generator.
- Note these API keys down, as they will be used for the Sensor password migration too, in all three environments.
- Reset the
PA_API_KEY_PRIMARY
environment variable for the development and production environments according to the values generated.