Link: Github Repository
Reach me out via LinkedIn, Portfolio Contact Form or mail@pascal-nehlsen.de
Conduit Pipeline with Github Actions
This repository builds upon this Conduit project and integrates a CI/CD pipeline.
This GitHub Actions pipeline automates the process of cloning a repository, building Docker images, and deploying an application to a remote server using Docker Compose.
Table of Contents
- Workflow Trigger
- Workflow Overview
- Steps in the Build Job
- Steps in the Deploy Job
- Secrets Required for Deployment
Workflow Trigger
The workflow is triggered under the following conditions:
-
Manual Trigger (workflow_dispatch): The workflow can be manually triggered from the GitHub Actions dashboard. -
Push to the main Branch: When a commit is pushed to the main branch, the workflow is automatically triggered. -
Workflow Call: The workflow can also be called from other workflows, requiring specific secrets:SSH_PRIVATE_KEY: The private SSH key for accessing the remote server.REMOTE_HOST: The IP address or hostname of the remote server.REMOTE_USER: The username for the remote server.TARGET: The target directory on the remote server where files will be uploaded.
Workflow Overview
The workflow consists of two main jobs (using existing github actions):
-
Build Job: This job builds and pushes Docker images for the frontend and backend of the application. The images are pushed to a Docker registry (GitHub Container Registry in this case).
-
Deploy Job: This job handles the deployment of the application to the remote server. The necessary artifacts (.env, docker-compose.yaml) are transferred, and the application is started on the remote server using Docker Compose.
Steps in the Build Job:
- Clone repository using actions/checkout to get the latest code
- Set up Docker Buildx with docker/setup-buildx-action for advanced build features
- Authenticate with GHCR using docker/login-action
- Extract metadata with docker/metadata-action to extract metadata
- Create .env file from example.env
- Build and push frontend & backend images with docker/build-push-action
- Upload deployment artifacts with actions/download-artifact (
.envanddocker-compose.yaml)
Steps in the Deploy Job:
- Clone repository using actions/checkout to get the latest code
- Download deployment artifacts with actions/download-artifact
- Transfer files via SCP using appleboy/scp-action to copy
.envanddocker-compose.yamlto the remote server - Deploy with SSH using appleboy/ssh-action:
- Stop old containers:
docker compose down --remove-orphans - Clean up unused resources:
docker system prune -af - Start containers:
docker compose up -d
- Stop old containers:
Secrets Required for Deployment:
SSH_PRIVATE_KEY: Private SSH key used for authenticating with the remote server.REMOTE_HOST: The IP address or domain of the remote server.REMOTE_USER: The username used to access the remote server.TARGET: The target directory on the remote server where the application will be deployed.GHCR_PAT: A GitHub Personal Access Token for authenticating with the GitHub Container Registry.