from GitHub

Deployments with GitHub Actions #

Requirements #

  • You need to have a GitHub Account/organization
  • You need to create a deploy user on our platform
  • Add the following private variables to the repository or organization secrets on GitHub:
    • QUANTUM_USER - your deployment user name
    • QUANTUM_PASSWORD

Basic Setup #

GitHub Actions uses workflows to run commands based on events. In this example, we want to deploy a stack when a (GitHub) pull request is merged into the main branch. To get this done, we are using the quantum-cli Github Action!

The file’s path (in your repository) is: .github/workflows/deployment.yml.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
name: deployment

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: checkout code
        uses: actions/checkout@v4
      - name: install/login with quantum-cli
        uses: hostwithquantum/setup-quantum-cli@main
        with:
          username: ${{ secrets.QUANTUM_USERNAME }}
          password: ${{ secrets.QUANTUM_PASSWORD }}
      - name: deploy stack
        run: quantum-cli stacks update --create --stack $QUANTUM_STACK --wait
        env:
          QUANTUM_USER: ${{ secrets.QUANTUM_USER }}
          QUANTUM_PASSWORD: ${{ secrets.QUANTUM_PASSWORD }}
          QUANTUM_ENDPOINT: "YOUR ENDPOINT"
          QUANTUM_STACK: "YOUR STACK"
Remember to customize QUANTUM_ENDPOINT and QUANTUM_STACK above.

Setup with custom Docker images #

If you need to build custom images, you will need a private registry. It’s up to you if you want to run a registry yourself or take advantage of Quantum’s managed Docker Registry.

GitHub Packages offers a Docker registry as well. Follow this link to learn more.

In addition to the example above, add the registry credentials as repository or organization secrets:

  • REGISTRY_USER
  • REGISTRY_PASSWORD

Add the following to the previous workflow to build and push a Docker image, before using quantum-cli to deploy it:

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    steps:
      - name: checkout code
        uses: actions/checkout@v4
      - name: set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name: Login to registry
        uses: docker/login-action@v3
        with:
          registry: registry.example.org
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
      - id: meta
        uses: docker/metadata-action@v5
        with:
          images: registry.example.org/project/app
      - name: "build: application"
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Avoid using :latest and inject a version into your stack. To do so, set an environment variable with the output from docker/metadata-action before you deploy:

- run: echo "VERSION=${{ steps.meta.output.version }}" >> $GITHUB_ENV

In the stack/compose file, use this as an example: image: registry.example.org/project/app:$VERSION.