-
-
Notifications
You must be signed in to change notification settings - Fork 806
203 lines (180 loc) · 7.31 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
name: OctoBot-Docker
on:
push:
branches:
- "master"
- "dev"
tags:
- "*"
pull_request:
jobs:
lint:
name: ubuntu-latest - Docker - lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run hadolint
uses: reviewdog/action-hadolint@v1
with:
github_token: ${{ secrets.github_token }}
hadolint_ignore: DL3013 DL3008
build_test_push:
needs: lint
name: ubuntu-latest - Docker - build & test & push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Environment Variables
run: |
OWNER="$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]' | tr -d '-')"
IMG=octobot
echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "IMAGE=${OWNER}/${IMG}" >> $GITHUB_ENV
echo "LATEST=latest" >> $GITHUB_ENV
echo "STAGING=staging" >> $GITHUB_ENV
echo "STABLE=stable" >> $GITHUB_ENV
echo "TEST=test" >> $GITHUB_ENV
echo "SHA=${GITHUB_SHA}" >> $GITHUB_ENV
echo "CONTAINER_NAME=octobot" >> $GITHUB_ENV
echo "CHECK_TENTACLE_CONTAINER_TIME=10" >> $GITHUB_ENV
echo "WAIT_CONTAINER_TIME=80" >> $GITHUB_ENV
- name: Wait for tentacles
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-tentacles
with:
token: ${{ secrets.AUTH_TOKEN }}
checkName: "ubuntu-latestx64 - Python - 3.10 - Upload"
ref: ${{ github.ref }}
repo: OctoBot-Tentacles
timeoutSeconds: 3600
- name: Trigger fail when Tentacles failed
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && steps.wait-for-tentacles.outputs.conclusion == 'failure'
run: exit 1
- name: Set up QEMU
id: qemu-setup
uses: docker/setup-qemu-action@master
with:
platforms: all
- name: Print available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
driver: docker-container
use: true
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.event_name == 'push'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build latest
if: github.event_name != 'push'
uses: docker/build-push-action@master
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64
# Using "load: true" forces the docker driver.
# Unfortunately, the "docker" driver does not support
# multi-platform builds.
load: true
push: false
tags: ${{ env.IMAGE }}:${{ env.SHA }}
build-args: |
TENTACLES_URL_TAG=${{ env.LATEST }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Docker build test container
if: github.event_name != 'push'
run: |
docker build -f ./tests/Dockerfile --build-arg OCTOBOT_IMAGE=${{ env.IMAGE }}:${{ env.SHA }} -t ${{ env.IMAGE }}:${{ env.TEST }} .
- name: run tests in docker
if: github.event_name != 'push'
run: |
docker run -i -e TENTACLES_REPOSITORY=dev-tentacles -e TENTACLES_URL_TAG=${GITHUB_HEAD_REF////_} -e DISABLE_SENTRY=True ${{ env.IMAGE }}:${{ env.TEST }}
- name: run and check health after start
if: github.event_name != 'push'
run: |
echo Start OctoBot docker with branche_name tentacles package
docker run -id -e TENTACLES_REPOSITORY=dev-tentacles -e TENTACLES_URL_TAG=${GITHUB_HEAD_REF////_} -e DISABLE_SENTRY=True --name ${{ env.CONTAINER_NAME }} ${{ env.IMAGE }}:${{ env.LATEST }}
sleep ${{ env.CHECK_TENTACLE_CONTAINER_TIME }}
if docker logs ${{ env.CONTAINER_NAME }} | grep "octobot_tentacles_manager.api.util.tentacles_management Failed to download file at url :" ; then
docker rm -f ${{ env.CONTAINER_NAME }}
echo Restarting docker with latest tentacle package...
docker run -id -e TENTACLES_URL_TAG=${{ env.LATEST }} -e DISABLE_SENTRY=True --name ${{ env.CONTAINER_NAME }} ${{ env.IMAGE }}:${{ env.LATEST }}
fi
sleep ${{ env.WAIT_CONTAINER_TIME }}
docker logs ${{ env.CONTAINER_NAME }}
docker inspect ${{ env.CONTAINER_NAME }} | jq '.[].State.Health.Status' | grep "healthy"
- name: Build and push latest
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags') && github.ref == 'refs/heads/dev'
uses: docker/build-push-action@master
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE }}:${{ env.LATEST }}
build-args: |
TENTACLES_URL_TAG=${{ env.LATEST }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push staging
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: docker/build-push-action@master
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE }}:${{ env.STAGING }}
build-args: |
TENTACLES_URL_TAG=${{ env.STABLE }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push on tag
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: docker/build-push-action@master
with:
context: .
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE }}:${{ env.LATEST }}
${{ env.IMAGE }}:${{ env.STABLE }}
${{ env.IMAGE }}:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
notify:
if: ${{ failure() }}
needs:
- lint
- build_test_push
uses: Drakkar-Software/.github/.github/workflows/failure_notify_workflow.yml@master
secrets:
DISCORD_GITHUB_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}
notify-dockerhub-update:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
name: Notify dockerhub update
runs-on: ubuntu-latest
needs:
- lint
- build_test_push
steps:
- name: Notify discord
uses: sarisia/actions-status-discord@v1
with:
description: "@here a new tag has been published on Docker Hub, docker bots can be updated."
webhook: ${{ secrets.DISCORD_GITHUB_WEBHOOK }}