generated from allenai/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 47
85 lines (72 loc) · 2.96 KB
/
docker_testing.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
# This workflow is just for building our Docker image for GPU testing on Beaker,
# and pushing it to Beaker. We only run it when the relevant Dockerfile (or .dockerignore) changes.
name: Docker testing
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
paths:
- 'Dockerfile.test'
- '.dockerignore'
- 'scripts/entrypoint.sh'
push:
branches:
- main
paths:
- 'Dockerfile.test'
- '.dockerignore'
- 'scripts/entrypoint.sh'
jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
BEAKER_TOKEN: ${{ secrets.BEAKER_TOKEN }}
BEAKER_WORKSPACE: ai2/tango-testing
IMAGE_NAME: tango-testing
steps:
- uses: actions/checkout@v3
- uses: allenai/setup-beaker@v2
with:
token: ${{ secrets.BEAKER_TOKEN }}
workspace: ${{ env.BEAKER_WORKSPACE }}
- name: Build Docker image
run: |
docker build -t "$IMAGE_NAME" -f Dockerfile.test .
- name: Determine current commit SHA (pull request)
if: github.event_name == 'pull_request'
run: |
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Determine current commit SHA (push)
if: github.event_name != 'pull_request'
run: |
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
- name: Test Docker image
run: |
docker run --rm --env COMMIT_SHA="$COMMIT_SHA" "$IMAGE_NAME" tango info
# In order to push a new version of an image to beaker, we have to delete the old version first.
# This doesn't actually delete the backing Docker image, so we'll still benefit from layer
# caching when we push new versions. But we have to be careful to minimize the amount
# of time between deletion and creation, because during that time any Beaker job trying to start
# that depends on that image will fail. So to minimize this downtime, we first push a
# "temp" version of the image, then delete the current one and quickly rename the "temp" one to take its place.
# The image might not exist yet though, so it's okay if the delete fails.
- name: Delete existing commit image
continue-on-error: true
run: |
beaker image delete petew/${{ env.IMAGE_NAME }}-${{ env.COMMIT_SHA }}
- name: Upload new commit image
run: |
beaker image create --workspace ${{ env.BEAKER_WORKSPACE }} --name ${{ env.IMAGE_NAME }}-${{ env.COMMIT_SHA }} ${{ env.IMAGE_NAME }}
- name: Delete existing image
if: github.event_name != 'pull_request'
continue-on-error: true
run: |
beaker image delete petew/${{ env.IMAGE_NAME }}
- name: Rename new commit image to final image
if: github.event_name != 'pull_request'
run: |
beaker image rename petew/${{ env.IMAGE_NAME }}-${{ env.COMMIT_SHA }} ${{ env.IMAGE_NAME }}