-
Notifications
You must be signed in to change notification settings - Fork 0
(3) How to Deploy
This repository uses GitHub Actions to automate the build and deployment process for the application. The following section explains the purpose of each workflow file and how they work together to handle deployment. The workflow file can be found under the .github folder
This file defines the workflow to build Docker containers for the application. The build process is triggered when there is a push to the main
branch or when invoked by another workflow. This workflow handles:
- Building Docker images for the application components (such as the server and client). It thereby uses the compose.yml file in the root directory.
- Pushing the built images to a Docker registry.
- Checkout Code: Retrieves the latest code from the repository.
- Set up Docker Buildx: Configures the Docker environment for building images.
- Log in to Docker Registry: Authenticates with the Docker registry using secrets. We are using the GitHub container registry to push and pull images (ghcr.io). The script automatically sets the GitHub actor and token to authenticate with the registry.
- Build and Push Images: Builds the Docker images for the client and server and pushes them to the registry.
This file defines the workflow for deploying the Docker containers to the production environment. It is dependent on the successful completion of the build_docker.yml
workflow. To connect to the VM the script uses the following secrets stored at Settings > Secrets and variables > Actions
:
-
SERVER_DOMAIN
: Domain of the VM to which you want to connect to (eg. ma-mang.ase.cit.tum.com). -
SERVER_USER
: User created on the VM which has permissions to create folders and run commands on the VM. -
SSH_KEY
: Private SSH key to establish a connection to the VM.
The following variables are used to enable a connection between GitHub and a VM running on the TUM's servers with a proxy gateway. Those variables are automatically set:
DEPLOYMENT_GATEWAY_HOST
DEPLOYMENT_GATEWAY_USER
DEPLOYMENT_GATEWAY_SSH_KEY
DEPLOYMENT_GATEWAY_PORT
- Connect to VM and Stop Docker Container: Execute docker compose down to stop the container for the deployment.
- Checkout Code: Retrieves the codebase to use for deployment configuration.
- Copy Docker Compose File to VM: Copy the compose.yml file from the root directory to the VM for later execution.
- Copy Letsencrypt Directory to VM: Copy the acme.json and the traefik.yml to the VM. These files are necessary to create a certificate to establish a TLS connection (LetsEncrypt)
-
Setting Up Environment Variables: Adds the environment variables specified in How to Setup to a .env file on the VM. You must define the varibales before at
Settings > Secrets and variables > Actions
as secrets. - Pull Docker Images: Pulls the built Docker images from the registry.
- Deploy to Production: Deploys the Docker containers to the production environment using the specified configuration by running docker compose.
- Notify on Success/Failure: Sends an email notification upon successful deployment or failure.
- Environment: Specifies the target environment for deployment (e.g., Production).
-
Server Image Tag: The Docker tag for the server image (e.g.,
latest
). -
Client Image Tag: The Docker tag for the client image (e.g.,
latest
).
This file (prod.yml
) combines the build and deployment workflows into a single process that is triggered on a push to the main
branch. It consists of two main jobs:
-
build-prod-container
: Usesbuild_docker.yml
to build and push Docker images. -
deploy-prod-container
: Depends on thebuild-prod-container
job and usesdeploy_docker.yml
to deploy the application to the production environment.
-
Trigger: The workflow is triggered by a push to the
main
branch. -
Job Sequence:
-
Build Docker Containers: The
build-prod-container
job builds and pushes the Docker images. -
Deploy Docker Containers: The
deploy-prod-container
job waits for the build to complete and then deploys the containers to the production environment.
-
Build Docker Containers: The
-
Set Up Secrets: Make sure the required secrets are added to the repository settings under
Settings > Secrets and variables > Actions
. These secrets are necessary for authenticating and performing operations like Docker image builds and deployments. These secrets include all environment variables for the server defined in How to Setup and theSERVER_DOMAIN
,SERVER_USER
,SSH_KEY
used in thedeploy_docker
workflow. -
Modify Configurations: Update the
docker-compose
configurations, image tags, environment variables, or any other parameters inbuild_docker.yml
anddeploy_docker.yml
according to your project’s requirements. -
Trigger Deployment: Push changes to the
main
branch to trigger theprod.yml
workflow. This will start the build and deployment process automatically.
-
Build Failures: Check the logs for the
build_docker.yml
workflow under the Actions tab to identify any issues during the Docker image build process. -
Deployment Failures: Review the logs for the
deploy_docker.yml
workflow to diagnose deployment issues. Ensure that the target environment is properly configured and accessible.