Skip to content

Continuous Deployment

Continuous deployment is the automated pipeline process spawned using GitHub Actions in order to deploy a production build of the code with a verified release tag, triggered by an event defined in the YML file. These actions are defined by you, the user, in the .github/workflows/continuous-deployment.yml file, which follows the GitHub Actions syntax.

Example Configuration File

name: Continous Deployment

on:
  push:
    branches: [main]

jobs:
  release-please:
    runs-on: ubuntu-latest
    steps:
      -
        name: Create release
        id: release-please 
        uses: google-github-actions/release-please-action@v3
        # Using Google's "release-please" action, checcks if new release required
        with:
          release-type: python
          package-name: sps-common
      -
        name: Checkout code
        if: ${{ steps.release-please.outputs.release_created }}
        # If the above step did return a need for release...
        uses: actions/checkout@v3
        with:
          fetch-depth: 1
      -
        name: Release Tags
        if: ${{ steps.release-please.outputs.release_created }}
        id: metadata
        # Putting data in metadata for use in following steps
        run: |
          echo "Creating release tags for docker-build"
          IMAGE="chimefrb/sps-common"
          TAG=${{ steps.release-please.outputs.tag_name }}
          echo image=${IMAGE}:latest >> $GITHUB_OUTPUT
          echo tagged_image=${IMAGE}:${TAG} >> $GITHUB_OUTPUT
      -
        name: Setup ssh-agent
        if: ${{ steps.release-please.outputs.release_created }}
        uses: webfactory/ssh-agent@v0.4.1
        id: ssh-agent-setup
        with:
          ssh-private-key: ${{ secrets.SPS_SSH_ID }}
      -
        name: Setup docker-buildx
        if: ${{ steps.release-please.outputs.release_created }}
        id: buildx
        uses: docker/setup-buildx-action@v1
        # Docker Buildx action to build our image from the repo's Dockerfile
        with:
          install: true
      -
        name: Perform DockerHub Login
        if: ${{ steps.release-please.outputs.release_created }}
        uses: docker/login-action@v1
        with:
        # More predefined GitHub Secrets to access DockerHub image storage
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      -
        name: Build & Push Production Image
        if: ${{ steps.release-please.outputs.release_created }}
        uses: docker/build-push-action@v3
        id: build-push-production
        with:
          context: .
          file: Dockerfile
          target: runtime
          tags: |
            ${{ steps.metadata.outputs.image }}
            ${{ steps.metadata.outputs.tagged_image }}
          ssh: "github_ssh_id=${{ steps.ssh-agent-setup.outputs.SSH_AUTH_SOCK}}"
          push: true
          cache-from: type=gha
          cache-to: type=gha,mode=max

Example Workflow Diagram