-
Notifications
You must be signed in to change notification settings - Fork 17
207 lines (187 loc) · 7.28 KB
/
docker.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Docker
# initially we would us on: [release] as well, the problem is that
# the code in clowder would not know what branch the code is in,
# and would not set the right version flags.
# This will run when:
# - when new code is pushed to master/develop 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:
- master
- develop
pull_request:
# Certain actions will only run when this is the master repo.
env:
MASTER_REPO: clowder-framework/clowder
DOCKERHUB_ORG: clowder
jobs:
docker:
runs-on: ubuntu-latest
env:
dockerhub: ${{ secrets.DOCKERHUB_USERNAME }}
permissions:
packages: write
strategy:
fail-fast: false
matrix:
name:
- clowder
- mongo-init
- monitor
- elasticsearch
include:
- name: clowder
FOLDER: "."
IMAGE: clowder
README: README.md
PLATFORM: "linux/amd64,linux/arm64"
- name: mongo-init
FOLDER: scripts/mongo-init
IMAGE: mongo-init
README: ""
PLATFORM: "linux/amd64"
- name: monitor
FOLDER: scripts/monitor
IMAGE: monitor
README: ""
PLATFORM: "linux/amd64,linux/arm64"
- name: elasticsearch
FOLDER: scripts/elasticsearch
IMAGE: elasticsearch
README: ""
PLATFORM: "linux/amd64"
steps:
- uses: actions/checkout@v3
# calculate some variables that are used later
- name: variable setup
run: |
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
if [ "$BRANCH" == "master" ]; then
version="$(awk '/version = / { print $4 }' project/Build.scala | sed 's/"//g')"
tags="latest"
oldversion=""
while [ "${oldversion}" != "${version}" ]; do
oldversion="${version}"
tags="${tags} ${version}"
version=${version%.*}
done
version="$(awk '/version = / { print $4 }' project/Build.scala | sed 's/"//g')"
elif [ "$BRANCH" == "develop" ]; then
version="develop"
tags="develop"
else
version="test"
tags="${BRANCH}"
fi
push_tags=""
for tag in ${tags}; do
if [ "${{ secrets.DOCKERHUB_USERNAME }}" != "" ]; then
push_tags="${push_tags}${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}:${tag},"
fi
push_tags="${push_tags}ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE }}:${tag},"
done
push_tags="${push_tags%,*}"
echo "BRANCH=${BRANCH}"
echo "VERSION=${version}"
echo "TAGS=${tags}"
echo "PUSH_TAGS=${push_tags}"
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "VERSION=${version}" >> $GITHUB_ENV
echo "TAGS=${push_tags}" >> $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 != ''
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 clowder docker images
- name: Build and push ${{ matrix.IMAGE }}-build
if: matrix.IMAGE == 'clowder'
uses: docker/build-push-action@v2
with:
push: true
context: ${{ matrix.FOLDER }}
platforms: ${{ matrix.PLATFORM }}
target: ${{ matrix.IMAGE }}-build
cache-from: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-build-cache:${{ env.BRANCH }}
cache-to: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-build-cache:${{ env.BRANCH }},mode=max
tags: ${{ env.TAGS }}
build-args: |
BRANCH=${{ env.BRANCH }}
VERSION=${{ env.VERSION }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
- name: Build and push ${{ matrix.IMAGE }}-runtime
if: matrix.IMAGE == 'clowder'
uses: docker/build-push-action@v2
with:
push: true
context: ${{ matrix.FOLDER }}
platforms: ${{ matrix.PLATFORM }}
target: ${{ matrix.IMAGE }}-runtime
cache-from: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-runtime-cache:${{ env.BRANCH }}
cache-to: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-runtime-cache:${{ env.BRANCH }}
tags: ${{ env.TAGS }}
build-args: |
BRANCH=${{ env.BRANCH }}
VERSION=${{ env.VERSION }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
# build the other docker images
- name: Build and push ${{ matrix.IMAGE }}
if: matrix.IMAGE != 'clowder'
uses: docker/build-push-action@v2
with:
push: true
context: ${{ matrix.FOLDER }}
platforms: ${{ matrix.PLATFORM }}
cache-from: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-cache:${{ env.BRANCH }}
cache-to: type=registry,ref=${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}-cache:${{ env.BRANCH }},mode=max
tags: ${{ env.TAGS }}
build-args: |
BRANCH=${{ env.BRANCH }}
VERSION=${{ env.VERSION }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
# update README at DockerHub
- name: Docker Hub Description
if: env.dockerhub != '' && matrix.README != '' && github.event_name == 'push' && github.repository == env.MASTER_REPO && env.BRANCH == 'master'
uses: peter-evans/dockerhub-description@v2
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}
README_FILEPATH: ${{ matrix.README }}