starlette-sqlite backend for github pages frontend
Guide assumes a Ubuntu based server
- [Remote]: Command should be run on the remote server
- [Local]: Command should be run locally on your pc
From a sudo-enabled user, run these commands:
- [Remote] Create user:
adduser <username>
, for password, usedefault123
Optional: Add user to sudoers:
usermod -aG sudo <username>
- [Remote] Switch to new user:
su <username>
- [Remote] Setup SSH:
mkdir ~/.ssh && touch ~/.ssh/authorized_keys
- Now see Generate and push a new SSH key to the server
- Use
passwd -e <username>
to force the user to choose a new password when they login the next timeUse
exit
to exit the new user and return to the sudo-enabled user
- [Local] On the employee's local machine, reuse an existing ssh key or generate a new one with
ssh-keygen -t rsa
, - [Local] Copy the contents of the generated
<key.pub>
file to the clipboard - [Remote] Authorize the key on the server by appending it to authorized_keys:
echo "<public key contents>" >> ~/.ssh/authorized_keys
- [Local] It should now be possible to authenticate with
ssh <username>@<host>
using the new ssh key on the employee's local machine
- [Remote] Create
/var/www/stadsarkiv
:sudo mkdir -p /var/www/stadsarkiv
- [Remote] Configure the user
www-data
:The user and group
www-data
should already exist on Ubuntu based distros.- Change ownership of
/var/www/
folder towww-data
user:sudo chown www-data:www-data -R /var/www
- Add user to
www-data
group:sudo adduser <user> www-data
- Change ownership of
- [Local] Cd into the repo-folder and copy to remote:
scp . <user>@<hostname>:/var/www/stadsarkiv
- [Remote] Enter the application directory:
cd /var/www/stadsarkiv
k5. [Remote] Start the application:sudo docker-compose -f docker-compose.production.yml -f docker-compose.yml up -d
We use Caddy as a reverse proxy to handle SSL and routing to the application.
- [Remote] Install Caddy by following the official guide
- [Remote] Create a Caddyfile in
/var/www/Caddyfile
with the following content (change the port to match the port used in the docker-compose file):<domain> { reverse_proxy :3000 }
- [Remote] Start Caddy:
cd /var/www && sudo caddy start
Note that we have set up github action workflows to do this automatically
- Run
poetry run push
to build and push a production image to azure. The image will be tagged with the current dateThe script only depends on poetry, so you can (and should) run it outside of the container, don't run 'poetry install' outside of the container :)
- SSH into the staging server and enter the project directory (
/var/www/stadsarkiv
) - Pull the new image:
docker compose -f docker-compose.production.yml -f docker-compose.yml pull
You might need to update the docker compose file. See SERVER.md on how to do this.
- Restart the application:
docker compose -f docker-compose.production.yml -f docker-compose.yml up -d