Repository containing workflow templates and other guidelines
Create a Dockerfile for all your services that you want to deploy.
Important
We want to maintain a consistent workflow for our docker images across all repositories and maintain it at a central place. Therefore, we provide a workflow that you can call in your repository without the need to copy the workflow file!
Create a new GitHub Actions workflow file (e.g., .github/workflows/build-and-push.yml) in your repository with the following content:
name: Build and Push Docker Image
on: # Adjust the triggers, conditions, etc. to your needs, see examples below
pull_request:
push:
branches: [main]
jobs:
# You can also build and push multiple images in parallel using a matrix (see examples)
build-and-push-workflow:
uses: ls1intum/.github/.github/workflows/build-and-push-docker-image.yml@main
with:
image-name: ls1intum/<repository-name>/<your-image-name> # Defaults to the repository name = <owner>/<repository-name>
docker-file: path/to/your/Dockerfile # Defaults to Dockerfile
secrets: inherit
Examples:
Hades
repository: build.ymlHephaestus
repository: build-and-push-docker.ymlApollon_standalone
repository: build-and-push.yml
Include the images from the registry and have IMAGE_TAG
as a placeholder for the image tag that you want to deploy, i.e. latest
, pr-233
, etc. A name for the compose file could be compose.prod.yaml
.
services:
<service-name-1>:
image: "ghcr.io/ls1intum/<repository-name>/<your-image-name>:${IMAGE_TAG}"
...
environment:
- SECRET_1=${SECRET_1}
- VAR_1=${VAR_1}
- VAR_2=${VAR_2}
...
...
name: Deploy to Development
on:
workflow_dispatch: # For manual triggers via the GitHub Actions UI
inputs:
image-tag:
type: string
description: "Image tag to deploy (default: pr-<number> if PR exists, latest for default branch)"
jobs:
deploy:
uses: ls1intum/.github/.github/workflows/deploy-docker-compose.yml@main
with:
environment: Development # Replace with your environment
docker-compose-file: "./docker-compose.prod.yml" # Path to your docker-compose file
main-image-name: ls1intum/<image-name> # For checking if images with image tag exist
image-tag: ${{ inputs.image-tag }}
env-file-name: .env.test1 # (Optional) Path to the .env file, defaults to .env
remove-volumes: false # (Optional) Remove volumes after stopping the services
secrets: inherit
Examples:
Hephaestus
repository: deploy-prod.yml
Prerequisites: VM exists at VM_HOST
and is accessible via SSH
- SSH into the VM:
ssh <your-user>@<VMHost>
- Create new user called
github_deployment
with:sudo adduser github_deployment --disabled-password
, you can leave all fields empty - Check if docker is installed:
sudo docker info
, if not install with these instructions - Add
github_deployment
to the docker group:sudo usermod -aG docker github_deployment
- Create the deployment directory
/opt/github
and givegithub_deployment
access:sudo mkdir /opt/github && sudo chown github_deployment:github_deployment /opt/github
- Switch to
github_deployment
user:sudo su github_deployment
- Generate a new SSH key on VM:
ssh-keygen -t ed25519 -C "github_deployment@<VMHost>"
, leave passphrase empty - Copy the public key to the authorized keys:
cat /home/github_deployment/.ssh/id_ed25519.pub > /home/github_deployment/.ssh/authorized_keys
- Copy the private key to your clipboard:
cat /home/github_deployment/.ssh/id_ed25519
- Go to your repository settings: https://github.com/ls1intum/repository-name/settings
- Click
Environments
thenNew environment
, if not already created - Setup the following secret:
VM_SSH_PRIVATE_KEY
: Paste the private key from the VM
- Setup the following variables:
VM_HOST
: The hostname of the VM, without protocol (e.g.,artemis.cit.tum.de
)VM_USERNAME
:github_deployment
, the user you created on the VM
- Set required reviewers (people or teams) that should approve the workflow run before it can be deployed to the environment. Note: Approval is needed if you are reading a protected environment
- Add your sensitive secrets to
Environment secrets
and your insensitive variables toEnvironment variables
- Caution: Variables will be visible in the logs, secrets will be automatically censored by GitHub
- Go to the
Actions
tab in your repository - Click on the
Deploy to Development
workflow - Click on
Run workflow
and enter the image tag you want to deploy, leave empty for default (pr-<number>
if PR exists,latest
for default branch) - Wait for the workflow to finish, approve the deployment if required