-
Notifications
You must be signed in to change notification settings - Fork 6
130 lines (129 loc) · 6.03 KB
/
docker-image.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
name: Docker Image CI
on:
push:
branches: ["master", "release/*"]
tags:
- "*"
pull_request:
types: [opened, synchronize]
jobs:
acas:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ github.repository }}-oss
- name: Set ACAS_TAG to ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
run: echo "ACAS_TAG=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# The following few steps figure out what version of acasclient to test with
# If main or release branch, run tests using matching release branch of acasclient
- name: Set ACAS_CLIENT_REF to the current branch ${{ github.ref }}
run: |
echo "ACAS_CLIENT_REF=$(echo ${{ github.ref }} | sed 's/refs\/heads\///g')" >> $GITHUB_ENV
if: github.event_name == 'push'
# If a PR, run tests on acasclient branch matching destination of PR
- name: Set ACAS_CLIENT_REF to the PR destination branch ${{ github.base_ref }}
run: |
echo "ACAS_CLIENT_REF=${{ github.base_ref }}" >> $GITHUB_ENV
if: github.event_name == 'pull_request'
# If a tag, run tests on acasclient branch by the same tag
- name: Set ACAS_CLIENT_REF to tag extracted from ${{ github.ref }}
run: |
ACAS_CLIENT_REF=$(echo ${{ github.ref }} | sed 's/refs\/tags\///')
echo "ACAS_CLIENT_REF=$ACAS_CLIENT_REF" >> $GITHUB_ENV
if: github.event_name == 'create'
# If on the "master" branch, run tests on the "main" branch of acasclient
- name: Override ACAS_CLIENT_REF if branch is "master"
run: |
echo "ACAS_CLIENT_REF=main" >> $GITHUB_ENV
if: github.ref == 'refs/heads/master'
- name: Checkout acasclient
uses: actions/checkout@v4
with:
repository: mcneilco/acasclient
path: acasclient
# Check out the branch specified by ACAS_CLIENT_REF
ref: ${{ env.ACAS_CLIENT_REF }}
- name: Build (no push)
uses: docker/build-push-action@v5
with:
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ env.ACAS_TAG }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
- name: Run docker compose up - assumes racas-oss:${{ env.ACAS_TAG }} and acas-roo-server-oss:${{ env.ACAS_TAG }}-indigo exist and are up to date
id: dockerComposeUp
run: |
echo "docker_compose_pull_failure=false" >> $GITHUB_OUTPUT
docker compose -f "docker-compose.yml" up -d || echo "docker_compose_pull_failure=true" >> $GITHUB_OUTPUT
- name: Get docker images fallback tag name
run: |
echo "DEFAULT_BRANCH_ACAS_TAG=$(echo ${{ github.event.repository.default_branch }} | sed -e 's/\//-/g')" >> $GITHUB_ENV
if: ${{ steps.dockerComposeUp.outputs.docker_compose_pull_failure == 'true' }}
- name: Falling back to ${{ env.DEFAULT_BRANCH_ACAS_TAG }} docker image tag for roo and racas tags
run: |
docker pull mcneilco/acas-roo-server-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG }}-indigo
docker tag mcneilco/acas-roo-server-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG}}-indigo mcneilco/acas-roo-server-oss:${{ env.ACAS_TAG }}-indigo
docker pull mcneilco/racas-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG}}
docker tag mcneilco/racas-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG }} mcneilco/racas-oss:${{ env.ACAS_TAG }}
docker compose -f "docker-compose.yml" up -d
if: ${{ steps.dockerComposeUp.outputs.docker_compose_pull_failure == 'true' }}
- name: Create docker bob
run: bash docker_bob_setup.sh
- name: Create bob credentials for acasclient
run: |
mkdir ~/.acas
echo "[default]" >> ~/.acas/credentials
echo "username=bob" >> ~/.acas/credentials
echo "password=secret" >> ~/.acas/credentials
echo "url=http://localhost:3000" >> ~/.acas/credentials
- name: Set Up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install acasclient and dependencies
run: |
python -m pip install --upgrade pip
pip install ./acasclient
- name: Run tests
run: python -m unittest discover -s ./acasclient -p "test_*.py" -v
- name: Build multi-arch and push
# Only push tags and release branches
if: ${{ startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
platforms: linux/amd64,linux/arm64/v8
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ env.ACAS_TAG }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}