-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (130 loc) · 4.49 KB
/
build.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
# Any commit to master branch re-builds images, re-runs tests, and pushes SHA tags to DockerHub
name: Build
on:
push:
branches:
- main
paths-ignore:
- 'LICENSE'
- 'README.md'
workflow_dispatch:
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_ORG: ${{ github.repository_owner }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
jobs:
build-base:
env:
IMAGE: base-image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Get date tag
id: get_date
run: |
DATE_TAG="$( date -u '+%Y.%m.%d' )"
echo "date_tag=$DATE_TAG" >> $GITHUB_OUTPUT
- name: Get registry and org
id: registry_org
run: |
ORG=$(echo "${{ env.DOCKER_ORG }}" | tr '[:upper:]' '[:lower:]')
echo "image_base=${{ env.DOCKER_REGISTRY }}/${ORG}" >> $GITHUB_OUTPUT
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
- name: Free up disk space
run: |
df -h
docker image ls
sudo apt clean
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
df -h
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ steps.registry_org.outputs.image_base }}/${{ env.IMAGE }}
tags: |
# set latest tag for default branch
type=raw,value=latest
type=raw,value=${{ steps.get_date.outputs.date_tag }}
- name: Log in to registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ${{ env.IMAGE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
build-images:
needs: build-base
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
IMAGE: [base-ssec-project,tutorial-scipy-2024]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get date tag
id: get_date
run: |
DATE_TAG="$( date -u '+%Y.%m.%d' )"
echo "date_tag=$DATE_TAG" >> $GITHUB_OUTPUT
- name: Get registry and org
id: registry_org
run: |
ORG=$(echo "${{ env.DOCKER_ORG }}" | tr '[:upper:]' '[:lower:]')
echo "image_base=${{ env.DOCKER_REGISTRY }}/${ORG}" >> $GITHUB_OUTPUT
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
- name: Free up disk space
run: |
df -h
docker image ls
sudo apt clean
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
df -h
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.registry_org.outputs.image_base }}/${{ matrix.IMAGE }}
tags: |
# set latest tag for default branch
type=raw,value=latest
type=raw,value=${{ steps.get_date.outputs.date_tag }}
- name: Log in to registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ${{ matrix.IMAGE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
- name: Inspect Image
run: |
docker run ${{ steps.registry_org.outputs.image_base }}/${{ matrix.IMAGE }}:latest conda list
docker images ls
- name: Test Image
run: |
docker run -u 1000 -w /srv/test -v $PWD:/srv/test ${{ steps.registry_org.outputs.image_base }}/${{ matrix.IMAGE }}:latest