-
Notifications
You must be signed in to change notification settings - Fork 0
248 lines (212 loc) · 7.35 KB
/
Copy pathdocker-publish.yml
File metadata and controls
248 lines (212 loc) · 7.35 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Build and publish a Docker image.
name: Build and publish docker images
on:
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
REGISTRY: ghcr.io
UV_VERSION: 0.7
PYTHON_VERSION: 3.12
JUPYTER_VERSION: 2025-04-14
# If you want to include custom documentation, create a fork of the repo below and link the forked repo here
NOMAD_DOCS_REPO: https://github.com/FAIRmat-NFDI/nomad-docs.git
# If you want to skip the tests for some plugins, add them to the list below
PLUGIN_TESTS_PLUGINS_TO_SKIP: |
workflowparsers
nomad_porous_materials
simulationworkflowschema
databaseparsers
soapnormalizer
eelsdbparser
atomisticparsers
nomad_aitoolkit
pynxtools_igor
permissions:
contents: write
packages: write
attestations: write
id-token: write
jobs:
# Job 1: Update Lock File
update-lockfile:
name: Update Python Lock File
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
submodules: true
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: ${{ env.UV_VERSION }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Update lock file
run: uv lock
# Commits any changes made to the lockfile
- name: Commit lock file changes
if: github.ref_type != 'tag'
run: |
git config --global user.name github-actions
git config --global user.email github-actions@github.com
git add uv.lock
if [[ `git status --porcelain` ]]; then
git commit -m "Update lockfile"
git push origin -o ci.skip # prevent triggering the pipeline again
fi
# Job 2: Run unit tests for all of the plugin
plugin_unit_tests:
name: Run plugin unit tests
needs: update-lockfile
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
group: [1, 2]
env:
PLUGIN_TESTS_CI_NODE_TOTAL: 2
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
submodules: true
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: ${{ env.UV_VERSION }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Run plugin tests
env:
PLUGIN_TESTS_CI_NODE_INDEX: ${{ matrix.group }}
run: |
# replace the yaml list with a string, use a `,` to separate the plugins
PLUGINS_STRING=$(echo "$PLUGIN_TESTS_PLUGINS_TO_SKIP" | tr '\n' ',' | sed 's/,$//')
uv run \
--extra plugins \
--with "nomad-plugin-tests" \
nomad-plugin-tests --plugins-to-skip "$PLUGINS_STRING"
# Job 3: Build and Push Docker Image
build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: update-lockfile
strategy:
fail-fast: false
matrix:
service: [app, jupyter]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
submodules: true
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}${{ matrix.service == 'jupyter' && '/jupyter' || '' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
build-args: |
UV_VERSION=${{ env.UV_VERSION }}
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
NOMAD_DOCS_REPO=${{ env.NOMAD_DOCS_REPO }}
JUPYTER_VERSION=${{ env.JUPYTER_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: ${{ matrix.service == 'jupyter' && 'jupyter' || 'final' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Set APP_IMAGE for app service
if: matrix.service == 'app'
run: |
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
echo "APP_IMAGE=$FIRST_TAG" >> $GITHUB_ENV
- name: Set JUPYTER_IMAGE for jupyter service
if: matrix.service == 'jupyter'
run: |
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
echo "JUPYTER_IMAGE=$FIRST_TAG" >> $GITHUB_ENV
outputs:
app_image: ${{ env.APP_IMAGE }}
jupyter_image: ${{ env.JUPYTER_IMAGE }}
# Job 4: Run example upload tests
example_upload_tests:
name: Run example upload tests
needs: build
runs-on: ubuntu-latest
env:
APP_IMAGE: ${{ needs.build.outputs.app_image }}
JUPYTER_IMAGE: ${{ needs.build.outputs.jupyter_image }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
submodules: true
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Start containers
working-directory: tests
run: |
docker compose up -d --quiet-pull
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: ${{ env.UV_VERSION }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: uv sync --all-extras
- name: Health check
run: |
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
secs=300 # Set interval (duration) in seconds.
endTime=$(( $(date +%s) + secs )) # Calculate end time.
check_app_health() {
curl -s localhost:8000/-/health > /dev/null
}
check_jupyter_health() {
curl -s localhost:8888/ > /dev/null
}
while [ $(date +%s) -lt $endTime ]; do # Loop until interval has elapsed.
if check_app_health && check_jupyter_health; then
echo "Both App and Jupyter health endpoints are responding correctly."
exit 0
else
echo "The App or Jupyter health endpoint is not responding. Retrying in 10 seconds..."
sleep 10
fi
done
echo "Timeout reached. The App or Jupyter health endpoint did not respond within 5 minutes."
echo "Fetching Docker logs for debugging..."
docker logs app # Output logs from the app container
docker logs jupyter # Output logs from the Jupyter container
exit 1
- name: Run tests
working-directory: tests
run: |
export PLUGINS_STRING=$(echo "$PLUGIN_TESTS_PLUGINS_TO_SKIP" | tr '\n' ',' | sed 's/,$//')
uv run --extra plugins pytest -p no:warnings -sv