-
Notifications
You must be signed in to change notification settings - Fork 3
165 lines (147 loc) · 5.56 KB
/
docker.yaml
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Docker
# This will run when:
# - when new code is pushed to main/staging to push the tags
# latest and develop
# - when a pull request is created and updated to make sure the
# Dockerfile is still valid.
# To be able to push to dockerhub, this execpts the following
# secrets to be set in the project:
# - DOCKERHUB_USERNAME : username that can push to the org
# - DOCKERHUB_PASSWORD : password asscoaited with the username
on:
push:
branches:
- main
- staging
- expt
pull_request:
# Certain actions will only run when this is the main repo.
env:
MAIN_REPO: classtranscribe/WebAPI
DOCKERHUB_ORG: classtranscribe
jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
name:
- api
- taskengine
- pythonrpcserver
include:
- name: api
FOLDER: "."
DOCKERFILE: API.Dockerfile
IMAGE: api
PLATFORM: "linux/amd64,linux/arm64"
- name: taskengine
FOLDER: "."
DOCKERFILE: TaskEngine.Dockerfile
IMAGE: taskengine
PLATFORM: "linux/amd64,linux/arm64"
- name: pythonrpcserver
FOLDER: "."
DOCKERFILE: pythonrpcserver.Dockerfile
IMAGE: pythonrpcserver
PLATFORM: "linux/amd64"
steps:
- uses: actions/checkout@v2
# calculate some variables that are used later
- name: version
run: |
# find out what the BRANCH is, in case of a PR we will use the PR-<number>
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
elif [[ $GITHUB_REF =~ pull ]]; then
BRANCH="$(echo $GITHUB_REF | sed 's#refs/pull/\([0-9]*\)/merge#PR-\1#')"
else
BRANCH=${GITHUB_REF##*/}
fi
# should we push to dockerhub, and is there a README
DOCKERHUB_PUSH="false"
DOCKERHUB_README="false"
if [ "${{ github.repository }}" == "${{ env.MAIN_REPO }}" ]; then
if [ "${{ secrets.DOCKERHUB_USERNAME }}" != "" -a "${{ secrets.DOCKERHUB_PASSWORD }}" != "" ]; then
DOCKERHUB_PUSH="true"
if [ -e "${{ matrix.FOLDER }}/README.md" ]; then
DOCKERHUB_README="true"
fi
fi
fi
# calculate the version and all tags
if [ "$BRANCH" == "main" ]; then
tags="latest $(date +'%Y%m%d') ${BRANCH}-${{ github.run_number }}"
else
tags="${BRANCH} ${BRANCH}-${{ github.run_number }}"
fi
# create a list of all images to be pushed
IMAGES=""
for tag in ${tags}; do
if [ "$DOCKERHUB_PUSH" == "true" ]; then
IMAGES="${IMAGES}${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}:${tag},"
fi
IMAGES="${IMAGES}ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE }}:${tag},"
done
IMAGES="${IMAGES%,*}"
# save the results in env
echo "BRANCH=${BRANCH}"
echo "DOCKERHUB_README=${DOCKERHUB_README}"
echo "DOCKERHUB_PUSH=${DOCKERHUB_PUSH}"
echo "IMAGES=${IMAGES}"
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "DOCKERHUB_README=${DOCKERHUB_README}" >> $GITHUB_ENV
echo "DOCKERHUB_PUSH=${DOCKERHUB_PUSH}" >> $GITHUB_ENV
echo "IMAGES=${IMAGES}" >> $GITHUB_ENV
# setup docker build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Inspect Builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
# login to registries
- name: Login to DockerHub
if: env.DOCKERHUB_PUSH == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# build the docker images
- name: Build and push ${{ matrix.name }}
uses: docker/build-push-action@v2
with:
push: true
context: ${{ matrix.FOLDER }}
file: ${{ matrix.DOCKERFILE }}
platforms: ${{ matrix.PLATFORM }}
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
tags: ${{ env.IMAGES }}
build-args: |
BRANCH: ${{ env.BRANCH }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
# this will update the README of the dockerhub repo
# - name: Docker Hub Description
# if: env.DOCKERHUB_README == 'true'
# uses: peter-evans/dockerhub-description@v2
# env:
# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
# DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
# DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_ORG }}/extractors-${{ matrix.NAME }}
# README_FILEPATH: ${{ matrix.FOLDER }}/README.md