-
Notifications
You must be signed in to change notification settings - Fork 1
161 lines (144 loc) · 5.64 KB
/
docker.yml
File metadata and controls
161 lines (144 loc) · 5.64 KB
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
name: Docker Images
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
schedule:
- cron: '1 0 * * 0'
release:
types: [published]
workflow_dispatch:
jobs:
docker:
name: Build and publish Docker images
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=neubauergroup/centos-python3
VERSION=latest
PYTHON_VERSION=3.9.9
REPO_NAME=${{github.repository}}
REPO_NAME_LOWERCASE="${REPO_NAME,,}"
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
TAGS="$TAGS,${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${PYTHON_VERSION},${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
# Releases also have GITHUB_REFs that are tags, so reuse VERSION
if [ "${{ github.event_name }}" = "release" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest-stable,ghcr.io/${REPO_NAME_LOWERCASE}:latest-stable,ghcr.io/${REPO_NAME_LOWERCASE}:${VERSION}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=repo_name_lowercase::"${REPO_NAME_LOWERCASE}"
echo ::set-output name=python_version::"${PYTHON_VERSION}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Test build
id: docker_build_test
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
load: true
push: false
- name: Image digest
run: echo ${{ steps.docker_build_test.outputs.digest }}
- name: List built images
run: docker images
- name: Check environment variables
run: >-
docker run --rm
neubauergroup/centos-python3:sha-${GITHUB_SHA::8}
'printenv'
- name: Check CPython version
run: >-
docker run --rm
neubauergroup/centos-python3:sha-${GITHUB_SHA::8}
'command -v python && \
echo "" && \
python --version --version && \
echo "" && \
python -m pip list'
- name: Check yum works
run: >-
docker run --rm
neubauergroup/centos-python3:sha-${GITHUB_SHA::8}
'yum --version && yum update -y'
- name: Check gcc finds /usr/local/include/python3.9/Python.h
run: >-
docker run --rm
-v $PWD:$PWD
-w $PWD
neubauergroup/centos-python3:sha-${GITHUB_SHA::8}
'gcc tests/test-gcc-include.c -o test-gcc-include && ./test-gcc-include && gcc --version'
- name: Check for shared python library (.so)
run: >-
docker run --rm
neubauergroup/centos-python3:sha-${GITHUB_SHA::8}
'find /usr/ -iname "*libpython3.*"'
- name: Build and publish to registry
# every PR will trigger a push event on main, so check the push event is actually coming from main
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'Neubauer-Group/centos-python3'
id: docker_build_latest
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
tags: |
neubauergroup/centos-python3:latest
neubauergroup/centos-python3:${{ steps.prep.outputs.python_version }}
ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:latest
ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:${{ steps.prep.outputs.python_version }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
push: true
- name: Build and publish to registry with release tag
if: github.event_name == 'release' && github.event.action == 'published' && github.repository == 'Neubauer-Group/centos-python3'
id: docker_build_release
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
push: true