CI/CD Workflow

The current project does not yet have a CI/CD workflow setup. The following steps are recommended to implement a continuous integration and continuous deployment (CI/CD) process using Docker/Compose and related technologies.

Step 1: Set Up a CI/CD Tool

Choose a CI/CD tool such as GitHub Actions, GitLab CI, Jenkins, or CircleCI. The tool should support Docker-based builds.

Step 2: Create CI/CD Pipeline Configuration

Below is an example GitHub Actions workflow file that can be used to automate the CI/CD process.

File: .github/workflows/ci-cd.yml

name: CI/CD Workflow

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1

    - name: Cache Docker layers
      uses: actions/cache@v2
      with:
        path: /tmp/.buildx-cache
        key: buildx-${{ github.sha }}
        restore-keys: |
          buildx-

    - name: Build Docker image
      run: |
        docker build \
          --build-arg GOLANGCI_LINT_VERSION=v1.55.2 \
          --file Dockerfile \
          --tag your-image-name:latest .

    - name: Run tests
      run: |
        docker run --rm your-image-name:latest make test

    - name: Lint code
      run: |
        docker run --rm your-image-name:latest make lint

    - name: Build the frontend
      run: |
        docker-compose up -d frontend

Step 3: Implement Docker Compose for Local Environments

The provided docker-compose.yml can be used to manage application services during development and testing.

File: docker-compose.yml

version: '3.8'

services:
  frontend:
    image: nginx
    container_name: frontend
    volumes:
      - project-data:/data

volumes:
  project-data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: "${TEST_DIR}"

Step 4: Script Build and Deployment

Utilize a Makefile to encapsulate the build and deployment steps, making execution straightforward for the CI/CD pipeline and local development.

File: Makefile

.PHONY: all build test lint deploy

all: build test lint

build:
    @echo "Building the Docker image..."
    docker build -t your-image-name:latest .

test:
    @echo "Running tests..."
    docker run --rm your-image-name:latest make test

lint:
    @echo "Running linter..."
    docker run --rm your-image-name:latest make lint

deploy:
    @echo "Deploying application..."
    docker-compose up -d

Next Steps

  1. Integrate the .github/workflows/ci-cd.yml into the project’s version control system.
  2. Modify the necessary parameters in the CI/CD configuration to reflect your project’s specific needs.
  3. Run the pipeline manually to ensure that all steps execute successfully.
  4. Regularly update the CI/CD configuration to incorporate new tests, deployments, and production checks as the project evolves.

By following these steps, a robust CI/CD workflow can be established using Docker and Compose to facilitate continuous integration and deployment.