Skip to content

Commit b3207bc

Browse files
committed
Add basic Docker deployment tests in GitHub actions to verify that Docker images/scripts are working properly.
1 parent 0333a10 commit b3207bc

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

.github/workflows/docker.yml

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,78 @@ jobs:
5757
# Enable redeploy of sandbox & demo if the branch for this image matches the deployment branch of
5858
# these sites as specified in reusable-docker-build.xml
5959
REDEPLOY_SANDBOX_URL: ${{ secrets.REDEPLOY_SANDBOX_URL }}
60-
REDEPLOY_DEMO_URL: ${{ secrets.REDEPLOY_DEMO_URL }}
60+
REDEPLOY_DEMO_URL: ${{ secrets.REDEPLOY_DEMO_URL }}
61+
62+
#################################################################################
63+
# Test Deployment via Docker to ensure newly built images are working properly
64+
#################################################################################
65+
docker-deploy:
66+
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular'
67+
if: github.repository == 'dspace/dspace-angular'
68+
runs-on: ubuntu-latest
69+
# Must run after all major images are built
70+
needs: [dspace-angular, dspace-angular-dist]
71+
env:
72+
# Override default dspace.server.url & REST 'host' because backend starts at http://127.0.0.1:8080
73+
dspace__P__server__P__url: http://127.0.0.1:8080/server
74+
DSPACE_REST_HOST: 127.0.0.1
75+
# Override default dspace.ui.url to also use 127.0.0.1.
76+
dspace__P__ui__P__url: http://127.0.0.1:4000
77+
# Docker Registry to use for Docker compose scripts below.
78+
# We use GitHub's Container Registry to avoid aggressive rate limits at DockerHub.
79+
DOCKER_REGISTRY: ghcr.io
80+
steps:
81+
# Checkout our codebase (to get access to Docker Compose scripts)
82+
- name: Checkout codebase
83+
uses: actions/checkout@v4
84+
# Download Docker image artifacts (which were just built by reusable-docker-build.yml)
85+
- name: Download Docker image artifacts
86+
uses: actions/download-artifact@v4
87+
with:
88+
# Download all amd64 Docker images (TAR files) into the /tmp/docker directory
89+
pattern: docker-image-*-linux-amd64
90+
path: /tmp/docker
91+
merge-multiple: true
92+
# Load each of the images into Docker by calling "docker image load" for each.
93+
# This ensures we are using the images just built & not any prior versions on DockerHub
94+
- name: Load all downloaded Docker images
95+
run: |
96+
find /tmp/docker -type f -name "*.tar" -exec docker image load --input "{}" \;
97+
docker image ls -a
98+
# Start backend using our compose script in the codebase.
99+
- name: Start production frontend and backend in Docker
100+
run: |
101+
docker compose -f docker/docker-compose-dist.yml -f docker/docker-compose-rest.yml up -d
102+
sleep 10
103+
docker container ls
104+
# Create a test admin account. Load test data from a simple set of AIPs as defined in cli.ingest.yml
105+
- name: Load test data into Backend
106+
run: |
107+
docker compose -f docker/cli.yml run --rm dspace-cli create-administrator -e test@test.edu -f admin -l user -p admin -c en
108+
docker compose -f docker/cli.yml -f docker/cli.ingest.yml run --rm dspace-cli
109+
# Verify backend started successfully.
110+
# 1. Make sure root endpoint is responding (check for dspace.name defined in docker-compose.yml)
111+
# 2. Also check /collections endpoint to ensure the test data loaded properly (check for a collection name in AIPs)
112+
- name: Verify backend is responding properly
113+
run: |
114+
result=$(wget -O- -q http://127.0.0.1:8080/server/api)
115+
echo "$result"
116+
echo "$result" | grep -oE "\"DSpace Started with Docker Compose\""
117+
result=$(wget -O- -q http://127.0.0.1:8080/server/api/core/collections)
118+
echo "$result"
119+
echo "$result" | grep -oE "\"Dog in Yard\""
120+
# Verify production frontend started successfully.
121+
# 1. Make sure /home path has "DSpace software" (this is in the footer of the page)
122+
# 2. Also check /community-list page lists one of the test Communities in the loaded test data
123+
- name: Verify frontend is responding properly
124+
run: |
125+
result=$(wget -O- -q http://127.0.0.1:4000/home)
126+
echo "$result"
127+
echo "$result" | grep -oE "\"DSpace software\""
128+
result=$(wget -O- -q http://127.0.0.1:4000/community-list)
129+
echo "$result"
130+
echo "$result" | grep -oE "\"Dog Photos Community\""
131+
# Shutdown our containers
132+
- name: Shutdown Docker containers
133+
run: |
134+
docker compose -f docker/docker-compose-dist.yml -f docker/docker-compose-rest.yml down

0 commit comments

Comments
 (0)