Skip to content

Commit f522a56

Browse files
authored
updated testing script & added workflow for nginx (#55)
* updated testing script & added workflow for nginx Changed nginx build to rely on local build, now only builds caches ui and nginx containers. upload_flat_folder_of_dicoms.py always uploads to localhost (for now) since that's where it's testing, and lastly setup test-upload-nginx.yml to run nginx testing on github actions
1 parent 10f4352 commit f522a56

File tree

7 files changed

+271
-168
lines changed

7 files changed

+271
-168
lines changed
Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
name: Docker Build (Nginx)
22

33
on:
4+
workflow_run:
5+
workflows: ["Docker Build (Local)"]
6+
types:
7+
- completed
48
push:
59
branches: [ '*' ]
610
pull_request:
711
branches: [ '*' ]
12+
workflow_dispatch:
813

914
env:
1015
DOCKER_BUILDKIT: 1
@@ -15,45 +20,55 @@ env:
1520
jobs:
1621
build:
1722
runs-on: ubuntu-latest
18-
outputs:
19-
images: ${{ steps.save-images.outputs.images }}
2023
steps:
2124
- uses: actions/checkout@v4
2225

2326
- name: Set repository name
2427
id: repo
2528
run: echo "REPO_NAME=$(basename $GITHUB_WORKSPACE)" >> $GITHUB_ENV
2629

27-
- name: Pull required images
28-
run: docker compose -f ${{ env.COMPOSE_FILE }} pull
30+
- name: Cache Docker images
31+
uses: actions/cache@v4
32+
id: docker-cache
33+
with:
34+
path: |
35+
mongo.tar
36+
api.tar
37+
handler.tar
38+
key: docker-local-images-${{ github.sha }}
39+
restore-keys: |
40+
docker-local-images-
41+
42+
- name: Load cached images
43+
if: steps.docker-cache.outputs.cache-hit == 'true'
44+
run: |
45+
# Load images and verify they were loaded successfully
46+
docker load < mongo.tar || exit 1
47+
rm mongo.tar
48+
docker load < api.tar || exit 1
49+
rm api.tar
50+
docker load < handler.tar || exit 1
51+
rm handler.tar
52+
53+
- name: Build UI with nginx
54+
run: docker compose -f ${{ env.COMPOSE_FILE }} build ui
2955

30-
- name: Build services
31-
run: docker compose -f ${{ env.COMPOSE_FILE }} build
56+
- name: Pull nginx image
57+
run: docker compose -f ${{ env.COMPOSE_FILE }} pull nginx
3258

3359
- name: Save images
34-
id: save-images
3560
run: |
36-
# Save images to tar files
37-
docker save mongo > mongo.tar
38-
docker save nginx > nginx.tar
39-
docker save ${REGISTRY_PREFIX}/${REPO_NAME}-api:latest > api-nginx.tar
40-
docker save ${REGISTRY_PREFIX}/${REPO_NAME}-handler:latest > handler-nginx.tar
61+
# Save all ui and nginx images to tar files
4162
docker save ${REGISTRY_PREFIX}/${REPO_NAME}-ui:latest > ui-nginx.tar
42-
43-
# Upload as artifacts
44-
echo "images=mongo.tar,api-nginx.tar,handler-nginx.tar,ui-nginx.tar,nginx.tar" >> $GITHUB_OUTPUT
45-
46-
- name: Upload images
47-
uses: actions/upload-artifact@v4
63+
docker save nginx > nginx.tar
64+
65+
- name: Cache Nginx images
66+
uses: actions/cache@v4
67+
id: nginx-cache
4868
with:
49-
name: docker-images-nginx
5069
path: |
51-
mongo.tar
52-
api-nginx.tar
53-
handler-nginx.tar
5470
ui-nginx.tar
5571
nginx.tar
56-
retention-days: 1
57-
58-
- name: Clean up
59-
run: docker system prune -f
72+
key: docker-nginx-images-${{ github.sha }}
73+
restore-keys: |
74+
docker-nginx-images-

.github/workflows/test-upload-local.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Test Local Upload
22

33
on:
4+
pull_request:
5+
branches: [ master ]
46
workflow_run:
57
workflows: ["Docker Build (Local)"]
68
types:
@@ -10,11 +12,12 @@ on:
1012
jobs:
1113
Test-Local-Uploads:
1214
runs-on: ubuntu-latest
13-
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
15+
if: ${{ github.event_name == 'pull_request' || github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
1416

1517
env:
1618
COMPOSE_FILE: ./docker-compose.yml
1719
REGISTRY_PREFIX: docker.io/library
20+
SERVER_NAME: localhost
1821

1922
steps:
2023
- uses: actions/checkout@v4
@@ -51,26 +54,33 @@ jobs:
5154
restore-keys: |
5255
docker-local-images-
5356
54-
- name: Load images
57+
- name: Setup environment
5558
run: |
56-
# Load images and verify they were loaded successfully
57-
docker load < mongo.tar || exit 1
58-
rm mongo.tar
59+
# copy the example.env to .env
60+
cp example.env .env
61+
62+
# Update .env to use the hostname
63+
sed -i "s/SERVER_NAME=.*/SERVER_NAME=localhost/" .env
64+
65+
- name: Build or load images
66+
run: |
67+
if [ -f mongo.tar ] && [ -f api.tar ] && [ -f handler.tar ] && [ -f ui.tar ]; then
68+
echo "Loading cached images..."
69+
if ! docker load < mongo.tar || ! docker load < api.tar || ! docker load < handler.tar || ! docker load < ui.tar; then
70+
echo "Failed to load cached images, building instead..."
71+
docker compose -f ${{ env.COMPOSE_FILE }} build
72+
else
73+
rm mongo.tar api.tar handler.tar ui.tar
74+
fi
75+
else
76+
echo "Building images..."
77+
docker compose -f ${{ env.COMPOSE_FILE }} build
78+
fi
5979
60-
docker load < api.tar || exit 1
61-
# Tag the API image to match docker-compose
80+
# Tag the images to match docker-compose
6281
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-api:latest api:latest
63-
rm api.tar
64-
65-
docker load < handler.tar || exit 1
66-
# Tag the handler image to match docker-compose
6782
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-handler:latest handler:latest
68-
rm handler.tar
69-
70-
docker load < ui.tar || exit 1
71-
# Tag the UI image to match docker-compose
7283
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-ui:latest ui:latest
73-
rm ui.tar
7484
7585
- name: Start services
7686
run: |
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Test Nginx Upload
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
workflow_run:
7+
workflows: ["Docker Build (Nginx)"]
8+
types:
9+
- completed
10+
workflow_dispatch: # Allow manual triggering
11+
12+
jobs:
13+
Test-Nginx-Uploads:
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event_name == 'pull_request' || github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
16+
17+
env:
18+
COMPOSE_FILE: ./docker-compose-nginx.yml
19+
REGISTRY_PREFIX: docker.io/library
20+
SERVER_NAME: localhost
21+
BRAINLIFE_USE_NGINX: "true"
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
submodules: true # Ensure we get the submodule info
27+
28+
- name: Set repository name
29+
run: echo "REPO_NAME=$(basename $GITHUB_WORKSPACE)" >> $GITHUB_ENV
30+
31+
- name: Cache test data
32+
uses: actions/cache@v4
33+
id: test-data-cache
34+
with:
35+
path: test/test_data
36+
key: test-data-${{ hashFiles('.gitmodules') }}
37+
restore-keys: |
38+
test-data-
39+
40+
- name: Get test data if not cached
41+
if: steps.test-data-cache.outputs.cache-hit != 'true'
42+
run: |
43+
make get-test-data
44+
45+
- name: Cache Docker images
46+
uses: actions/cache@v4
47+
id: docker-cache
48+
with:
49+
path: |
50+
mongo.tar
51+
api.tar
52+
handler.tar
53+
key: docker-local-images-${{ github.event.workflow_run.head_sha || github.sha }}
54+
restore-keys: |
55+
docker-local-images-
56+
57+
- name: Cache Nginx images
58+
uses: actions/cache@v4
59+
id: nginx-cache
60+
with:
61+
path: |
62+
ui-nginx.tar
63+
nginx.tar
64+
key: docker-nginx-images-${{ github.event.workflow_run.head_sha || github.sha }}
65+
restore-keys: |
66+
docker-nginx-images-
67+
68+
- name: Setup environment
69+
run: |
70+
# copy the example.env to .env
71+
cp example.env .env
72+
73+
# Update .env to use the hostname
74+
sed -i "s/SERVER_NAME=.*/SERVER_NAME=localhost/" .env
75+
sed -i "s/BRAINLIFE_USE_NGINX=.*/BRAINLIFE_USE_NGINX=true/" .env
76+
77+
- name: Build or load base images
78+
run: |
79+
if [ -f mongo.tar ] && [ -f api.tar ] && [ -f handler.tar ]; then
80+
echo "Loading cached base images..."
81+
if ! docker load < mongo.tar || ! docker load < api.tar || ! docker load < handler.tar; then
82+
echo "Failed to load cached images, building instead..."
83+
docker compose -f ${{ env.COMPOSE_FILE }} build
84+
else
85+
rm mongo.tar api.tar handler.tar
86+
fi
87+
else
88+
echo "Building base images..."
89+
docker compose -f ${{ env.COMPOSE_FILE }} build
90+
fi
91+
92+
# Tag the images to match docker-compose
93+
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-api:latest api:latest
94+
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-handler:latest handler:latest
95+
96+
- name: Build or load nginx images
97+
run: |
98+
if [ -f ui-nginx.tar ] && [ -f nginx.tar ]; then
99+
echo "Loading cached nginx images..."
100+
if ! docker load < ui-nginx.tar || ! docker load < nginx.tar; then
101+
echo "Failed to load cached nginx images, building instead..."
102+
docker compose -f ${{ env.COMPOSE_FILE }} build
103+
else
104+
rm ui-nginx.tar nginx.tar
105+
fi
106+
else
107+
echo "Building nginx images..."
108+
docker compose -f ${{ env.COMPOSE_FILE }} build
109+
fi
110+
111+
# Tag the UI image to match docker-compose
112+
docker tag ${REGISTRY_PREFIX}/${REPO_NAME}-ui:latest ui:latest
113+
114+
- name: Do additional Nginx setup
115+
run: |
116+
# create self signed certs using the hostname
117+
./create_self_signed_certs.sh localhost
118+
119+
- name: Start services
120+
run: |
121+
# Create and set permissions for temp directory
122+
mkdir -p /tmp/ezbids-workdir
123+
chmod 770 /tmp/ezbids-workdir
124+
125+
# Start services using our tagged images
126+
./launch.sh --daemon
127+
sleep 30
128+
129+
- name: Install uv
130+
run: |
131+
curl -LsSf https://astral.sh/uv/install.sh | sh
132+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
133+
134+
- name: Verify uv installation
135+
run: uv --version
136+
137+
- name: Run upload test
138+
run: |
139+
make test-upload

docker-compose-nginx.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ services:
6969
environment:
7070
VITE_APIHOST: https://${SERVER_NAME}/api
7171
VITE_BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION:-false}
72+
BRAINLIFE_USE_NGINX: true
7273
volumes:
7374
- ui_dist:/ui/dist
7475
command: tail -f /dev/null # Keep container running

0 commit comments

Comments
 (0)