ERAS Deployment Process - JU-DEV-Bootcamps/ERAS GitHub Wiki
As we can see there are multiple stages during the deployment process, to configure EC2 and Github Actions we can follow the next wiki pages:
Implement deployment Process
EC2 Configuration
The commands to install docker on the EC2 ubuntu instance were:
sudo apt update && sudo apt upgrade -y
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker ubuntu
Install docker compose (v2.32.4) for managing containers
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.32.4/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
The security group inbound rules were changed for the instance:
- PORTS: 80 - HTTP, 443 - HTTPS (Frontend - SPA access)
- PORTS: 8443 - TCP (Keycloak server)
- PORT: 8080 - TCP (Backend - swagger access - without SSL)
Deployment Automatic Process
The deployment project is based on Docker containers running on the EC2 instance, configured and initialized by a Docker Compose file. To achieve the automatic process, the workflow creates a file in JSON notation with the tags for the BE and FE and their versions (short commits for submodules) that are currently added to the ERAS repository. This file is called versions.json
.
Once this file is created at the ~/deploy location on the EC2 instance, the workflow uses two bash script files to complete the required steps:
- setVersions.sh: This file uses the versions file to create a new .env file used in the Docker Compose with the updated versions (if any).
- containers.sh: This file executes all the necessary Docker commands to stop, re-run, and clean up unused images or containers in the instance.
That's how the automatic deployment process is completed. However, if you want to manually set different image versions and run them for test purposes, you should look for the ~/app/.env file and set the required image tag versions for the BE or FE there. Then manually run the commands to bring down and bring up the Docker Compose.
Steps to Complete a Successful Deployment
By using the workflows stablished at each repository, the deployment process should be completed successfully.
Workflows
Initially, within the ERAS repository, the workflow is responsible for capturing the commit references of submodules for each repository and setting these as the versions to be deployed on the EC2 instance. This process is initiated whenever a change is pushed to the main branch.
If a change is pushed to the main branch but doesn't alter the commit references for the submodules, the workflow will still be initiated. However, since there are no changes in the versions for BE and FE, the containers on the EC2 instance will restart with the same versions. If changes were made to the image generated for the versions, the updated image will be pulled and used to run the containers.
The workflows in each submodule repository are responsible for building and pushing the corresponding images. During this process, the secrets and variables set in the repositories are replaced in the building image process and can be inspected to ensure the resulting image has the expected or required changes in these configurations.
Changing Secrets & Vars - Rerunning workflows
All the repositories have secrets and variables created to be used in workflows, some of which are used in the configurations for the images as mentioned earlier. If you need to change or update any of these variables, go to the repository, navigate to the 'Settings' tab, and find the 'Secrets & variables' dropdown in the sidebar menu. Click on the 'Actions' option to view and modify the defined secrets and variables.
To re-run a workflow and use the updated secrets/vars, simply click on the result status from the last workflow execution and enter the details for the required step:
Then, you can choose whether to re-run all the jobs related to the workflow execution or just re-run the desired step, such as the image creation at the package step: