GitHub, DockerHub and StackOS Integration
Using GitHub Actions, you can automate the building of your application and streamline the docker image creation and updating process.

GitHub Actions

Enable Github Actions for your GitHub Repository

Docker Hub Secrets

After logging in to Docker Hub go to: https://hub.docker.com/settings/security
Create a token by clicking "New Access Token"
Give your access token a name and Generate
Retain the following information for configuration into Github Actions 1) Your username and 2) the personal access token

GitHub Secrets

To automatically upload the results of your Docker Image Build to Docker Hub, configure secrets into the target respository. These Docker Hub secrets will be used to upload you image to Docker Hub.
Insert the information from Docker Hub into "Environment secrets" on Github Environments named "docker"

Set up GitHub Workflow

In your repo set up a file named .github/workflows/ci.yaml, and replace the values of "DOCKERHUB_USERNAME" and "DOCKERHUB_IMAGENAME" in the code below
1
name: ci
2
3
on:
4
push:
5
branches:
6
- '**'
7
tags:
8
- 'v*.*.*'
9
pull_request:
10
branches:
11
- 'main'
12
13
jobs:
14
docker:
15
environment: docker
16
runs-on: ubuntu-latest
17
steps:
18
-
19
name: Checkout
20
uses: actions/[email protected]
21
-
22
name: Docker meta
23
id: meta
24
uses: docker/[email protected]
25
with:
26
# list of Docker images to use as base name for tags
27
images: |
28
DOCKERHUB_USERNAME/DOCKERHUB_IMAGENAME
29
# generate Docker tags based on the following events/attributes
30
tags: |
31
type=schedule
32
type=ref,event=branch
33
type=ref,event=pr
34
type=semver,pattern={{version}}
35
type=semver,pattern={{major}}.{{minor}}
36
type=semver,pattern={{major}}
37
type=sha
38
-
39
name: Set up QEMU
40
uses: docker/[email protected]
41
-
42
name: Set up Docker Buildx
43
uses: docker/[email protected]
44
-
45
name: Login to DockerHub
46
if: github.event_name != 'pull_request'
47
uses: docker/[email protected]
48
with:
49
username: ${{ secrets.DOCKERHUB_USERNAME }}
50
password: ${{ secrets.DOCKERHUB_TOKEN }}
51
-
52
name: Build and push
53
uses: docker/[email protected]
54
with:
55
context: .
56
push: ${{ github.event_name != 'pull_request' }}
57
tags: ${{ steps.meta.outputs.tags }}
58
labels: ${{ steps.meta.outputs.labels }}
59
Copied!

Create a Dockerfile

For example, if you have a static website or PHP application you could create a Dockerfile in the root of your repository like this:
1
FROM php:7.4-apache
2
COPY . /var/www/html
Copied!
For node based applications a variation of this pattern could be useful:
1
FROM node:alpine
2
WORKDIR /app
3
COPY package.json ./
4
COPY package-lock.json ./
5
COPY ./ ./
6
RUN npm i
7
CMD ["npm", "run", "start"]
Copied!

Tag and Push to GitHub

After you commit your code, tag the current version like this:
1
git tag v1.2.3
Copied!
Then push the code to github, for example:
1
git push origin --tags
Copied!
Github will then run actions automatically to deploy (or show you errors)
If you see an error like this:
Edit the file .github/workflows/ci.yaml, and replace the values of "DOCKERHUB_USERNAME" and "DOCKERHUB_IMAGENAME"

Locate image in Docker Hub

You can verify the image appears in DockerHub by logging in and checking your profile
And you can also verify the tags that are automatically pushed to Docker Hub
The docker image tag, which is based on your git repository tag is useful for specifying the active image that should be used in StackOS.
Note: Do NOT use latest as the "latest" tag will only be downloaded once. Specify the version label such as "0.0.2". It will be a little more work, but this practice will also save you when you need to quickly roll back to a known version.
If you have not yet funded your account you can do so at this point to reserve resources to deploy your pods
If you are launching your pod for the first time, here's a quick guide