Overview
In this project, CI/CD automation is accomplished through a series of GitHub Actions workflows that leverage docker/build-push-action
for building and pushing Docker images. The relevant workflows and supporting scripts are organized under the .github/workflows/
directory, with specific tasks outlined for continuous integration, end-to-end (e2e) testing, and publishing.
Workflow Automation Scripts
1. Continuous Integration Workflow: .github/workflows/ci.yml
This workflow handles the Continuous Integration (CI) process. It is responsible for building the application and running tests. Here’s a breakdown of a typical setup:
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: yarn install
- name: Run lint
run: yarn lint
- name: Run tests
run: yarn test
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: false
The workflow triggers on pushes to the main
branch and for pull requests. It checks out the code, sets up the Node.js environment, installs dependencies, runs linters and tests, and finally builds the Docker image.
2. End-to-End Workflow: .github/workflows/e2e.yml
The end-to-end tests are managed in this workflow. It is designed to run comprehensive tests against the application in a real-world-like scenario.
name: E2E Tests
on:
push:
branches:
- main
- develop
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Build Docker images
uses: docker/build-push-action@v3
with:
context: .
file: test/Dockerfile
push: false
- name: Run e2e tests
run: yarn e2e
This workflow is triggered on pushes to both main
and develop
branches. It checks out the code, sets up Docker, builds the necessary images, and finally executes the end-to-end tests.
3. Publish Workflow: .github/workflows/publish.yml
This workflow is catered to the publishing stage of the CI/CD pipeline. It handles the logic of pushing the built Docker image to a container registry.
name: Publish
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: true
tags: your_image_name:latest
This workflow is triggered when a release is published. It checks out the code and utilizes the docker/build-push-action
to build and push the Docker image with the latest tag.
Additional Scripts
4. Dockerfile
The project’s Dockerfile is a simple setup that derives from Alpine and currently just echoes a message. Generally, it will be modified to set up the application environment.
# syntax=docker/dockerfile:1
FROM alpine
RUN echo "Hello world!"
5. Docker Compose Configuration
For local development or testing, a docker-compose.yml
file might be used to run services such as Nexus for storage.
version: '3'
services:
nexus:
image: sonatype/nexus3:${NEXUS_VERSION:-latest}
volumes:
- "./data:/nexus-data"
ports:
- "8081:8081"
- "8082:8082"
Conclusion
At this time, CI/CD automation is fully established within the project through the defined workflows. If there is no existing CI/CD setup, consider implementing similar workflows based on the examples discussed. The use of these scripts will streamline the build, test, and push processes, ensuring a smooth project lifecycle.
References
- GitHub Actions: docker/build-push-action