Skip to content

Commit 7a98f9a

Browse files
KasinhouMatus Kasak
andauthored
JCU/Customize docker (#1334)
* Change files to our pipeline * Added deploy, playwright tests to workflows * Added start.sh, updated workflows * Fix SSR check * Fix versions * Keeping higher versions * Fix ssr host --------- Co-authored-by: Matus Kasak <matus.kasak@dataquest.sk>
1 parent 419f34b commit 7a98f9a

6 files changed

Lines changed: 327 additions & 192 deletions

File tree

.github/workflows/build.yml

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs
44
name: Build
55

6-
# Run this Build for all pushes / PRs to current branch
7-
on: [push, pull_request]
6+
# Run this Build for pushes to our main and all PRs
7+
on:
8+
push:
9+
branches:
10+
- dtq-dev
11+
- customer/*
12+
pull_request:
13+
workflow_dispatch:
814

915
permissions:
1016
contents: read # to fetch code (actions/checkout)
@@ -24,6 +30,8 @@ jobs:
2430
# Spin up UI on 127.0.0.1 to avoid host resolution issues in e2e tests with Node 20+
2531
DSPACE_UI_HOST: 127.0.0.1
2632
DSPACE_UI_PORT: 4000
33+
# SSR only renders when the request Host matches ui.baseUrl's host. Set it explicitly to
34+
# the 127.0.0.1 host the e2e/SSR checks use; otherwise SSR falls back to CSR.
2735
DSPACE_UI_BASEURL: http://127.0.0.1:4000
2836
# Ensure all SSR caching is disabled in test environment
2937
DSPACE_CACHE_SERVERSIDE_BOTCACHE_MAX: 0
@@ -40,11 +48,8 @@ jobs:
4048
# Project name to use when running "docker compose" prior to e2e tests
4149
COMPOSE_PROJECT_NAME: 'ci'
4250
# Docker Registry to use for Docker compose scripts below.
43-
# On the upstream dspace/dspace-angular repository we use GitHub's Container Registry
44-
# (ghcr.io) to avoid aggressive rate limits at DockerHub. Forks cannot authenticate
45-
# against ghcr.io/dspace/* with their own GITHUB_TOKEN (and the images there require
46-
# auth), so on forks we fall back to docker.io where the same images are public.
47-
DOCKER_REGISTRY: ${{ github.repository == 'dspace/dspace-angular' && 'ghcr.io' || 'docker.io' }}
51+
# Using DockerHub as the images are publicly available there
52+
DOCKER_REGISTRY: docker.io
4853
strategy:
4954
# Create a matrix of Node versions to test against (in parallel)
5055
matrix:
@@ -124,18 +129,14 @@ jobs:
124129
path: 'coverage/dspace-angular/lcov.info'
125130
retention-days: 14
126131

127-
# Login to our Docker registry, so that we can access Docker images using "docker compose" below.
128-
# This login is required on the upstream repository because DOCKER_REGISTRY is set to ghcr.io
129-
# and pulling ghcr.io/dspace/* requires authentication. On forks, DOCKER_REGISTRY falls back to
130-
# docker.io (see env block above) where the same images are publicly pullable without a login,
131-
# and forks cannot authenticate against ghcr.io/dspace/* with their own GITHUB_TOKEN anyway.
132-
- name: Login to ${{ env.DOCKER_REGISTRY }}
133-
uses: docker/login-action@v4
134-
if: github.repository == 'dspace/dspace-angular'
135-
with:
136-
registry: ${{ env.DOCKER_REGISTRY }}
137-
username: ${{ github.repository_owner }}
138-
password: ${{ secrets.GITHUB_TOKEN }}
132+
# Note: Docker login not required for public images from docker.io
133+
# If you need to use ghcr.io images, uncomment the login step below:
134+
# - name: Login to ${{ env.DOCKER_REGISTRY }}
135+
# uses: docker/login-action@v3
136+
# with:
137+
# registry: ${{ env.DOCKER_REGISTRY }}
138+
# username: ${{ github.repository_owner }}
139+
# password: ${{ secrets.GITHUB_TOKEN }}
139140

140141
# Using "docker compose" start backend using CI configuration
141142
# and load assetstore from a cached copy
@@ -315,40 +316,3 @@ jobs:
315316

316317
- name: Shutdown Docker containers
317318
run: docker compose -f ./docker/docker-compose-ci.yml down
318-
319-
# Codecov upload is a separate job in order to allow us to restart this separate from the entire build/test
320-
# job above. This is necessary because Codecov uploads seem to randomly fail at times.
321-
# See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
322-
codecov:
323-
# Must run after 'tests' job above
324-
needs: tests
325-
# Only run on the upstream repository: forks do not have the CODECOV_TOKEN secret,
326-
# and Codecov refuses to create a commit on a protected branch without a token.
327-
if: github.repository == 'dspace/dspace-angular'
328-
runs-on: ubuntu-latest
329-
steps:
330-
- name: Checkout
331-
uses: actions/checkout@v6
332-
333-
# Download artifacts from previous 'tests' job
334-
- name: Download coverage artifacts
335-
uses: actions/download-artifact@v8
336-
337-
# Now attempt upload to Codecov using its action.
338-
# NOTE: We use a retry action to retry the Codecov upload if it fails the first time.
339-
#
340-
# Retry action: https://github.com/marketplace/actions/retry-action
341-
# Codecov action: https://github.com/codecov/codecov-action
342-
- name: Upload coverage to Codecov.io
343-
uses: Wandalen/wretry.action@v3.8.0
344-
with:
345-
action: codecov/codecov-action@v4
346-
# Ensure codecov-action throws an error when it fails to upload
347-
# This allows us to auto-restart the action if an error is thrown
348-
with: |
349-
fail_ci_if_error: true
350-
token: ${{ secrets.CODECOV_TOKEN }}
351-
# Try re-running action 5 times max
352-
attempt_limit: 5
353-
# Run again in 30 seconds
354-
attempt_delay: 30000

.github/workflows/deploy.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# DSpace Docker deploy on dataquest servers
2+
name: Deploy DSpace
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
DEV_MACHINE:
8+
required: false
9+
type: string
10+
default: 'dev-6'
11+
INSTANCE:
12+
required: false
13+
type: string
14+
default: '8593'
15+
IMPORT:
16+
required: false
17+
default: false
18+
type: boolean
19+
ERASE_DB:
20+
required: false
21+
default: false
22+
type: boolean
23+
24+
workflow_dispatch:
25+
inputs:
26+
INSTANCE:
27+
required: true
28+
default: '8593'
29+
type: choice
30+
options:
31+
- '8593'
32+
IMPORT:
33+
required: true
34+
default: true
35+
type: boolean
36+
ERASE_DB:
37+
required: false
38+
default: false
39+
type: boolean
40+
DEV_MACHINE:
41+
required: false
42+
type: string
43+
default: 'dev-6'
44+
45+
jobs:
46+
deploy-3:
47+
if: inputs.INSTANCE == '*' || inputs.INSTANCE == '8593'
48+
runs-on: dspace-${{inputs.DEV_MACHINE}}-dep-1
49+
timeout-minutes: 60
50+
env:
51+
INSTANCE: '8593'
52+
CONFIG_PATH: /opt/dspace-envs/${{inputs.INSTANCE}}
53+
ENVFILE: /opt/dspace-envs/${{inputs.INSTANCE}}/.env
54+
steps:
55+
- uses: actions/checkout@v6
56+
57+
- uses: ./.github/actions/erase-db
58+
if: inputs.ERASE_DB
59+
with:
60+
INSTANCE: ${{ env.INSTANCE }}
61+
NAME: dspace-${{ env.INSTANCE }}
62+
63+
- name: Set start.sh as executable
64+
run: chmod +x build-scripts/run/start.sh
65+
66+
- name: deploy to ${{inputs.DEV_MACHINE}}
67+
working-directory: build-scripts/run/
68+
env:
69+
ADMIN_PASSWORD: ${{ secrets.DSPACE_ADMIN_PASSWORD }}
70+
USER_PASSWORD: ${{ secrets.DSPACE_USER_PASSWORD }}
71+
run: |
72+
./start.sh dspace-$INSTANCE
73+
cd ../..
74+
docker compose --env-file $ENVFILE -p dspace-$INSTANCE -f docker/docker-compose.yml -f docker/docker-compose-rest.yml -f $CONFIG_PATH/docker-compose-rest.yml -f $CONFIG_PATH/docker-compose.yml up -d --no-build --remove-orphans
75+
76+
playwright-after-deploy3:
77+
needs: deploy-3
78+
if: '!inputs.IMPORT'
79+
uses: ./.github/workflows/playwright-tests.yml
80+
secrets: inherit
81+
82+
playwright-after-import3:
83+
needs: import-3
84+
if: inputs.IMPORT
85+
uses: ./.github/workflows/playwright-tests.yml
86+
secrets: inherit
87+
88+
import-3:
89+
runs-on: dspace-${{inputs.DEV_MACHINE}}-dep-1
90+
if: inputs.IMPORT
91+
timeout-minutes: 900
92+
needs: deploy-3
93+
env:
94+
INSTANCE: ${{inputs.INSTANCE}}
95+
CONFIG_PATH: /opt/dspace-envs/
96+
FNAME: old_dump.sql
97+
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
98+
steps:
99+
- name: vanilla import
100+
run: |
101+
export DATADIR=$CONFIG_PATH/${{inputs.INSTANCE}}/dump/$FNAME
102+
export DNAME=dspace${{inputs.INSTANCE}}
103+
export DDBNAME=dspacedb${{inputs.INSTANCE}}
104+
105+
docker stop $DNAME || true
106+
107+
echo "====="
108+
# echo Starting vanilla import DB
109+
docker cp $DATADIR $DDBNAME:/tmp/$FNAME
110+
111+
echo "Copying script for setup db roles to container..."
112+
113+
# Create database, import dumpand extensions, then cleanup
114+
docker exec $DDBNAME /bin/bash -c "
115+
dropdb -U dspace -p 10593 dspace || true &&
116+
createdb -U dspace -p 10593 --owner=dspace --encoding=UNICODE dspace &&
117+
psql -p 10593 -U dspace -d dspace -f /tmp/$FNAME
118+
"
119+
echo "====="
120+
docker start $DNAME
121+
122+
- name: run database migration
123+
run: |
124+
export DNAME=dspace${{inputs.INSTANCE}}
125+
export DDBNAME=dspacedb${{inputs.INSTANCE}}
126+
export SYNCSEQSETUP=$CONFIG_PATH/${{inputs.INSTANCE}}/$SYNCSEQFNAME
127+
128+
echo "Starting DSpace container for migration..."
129+
docker start $DNAME
130+
131+
echo "Waiting longer for DSpace to be fully ready and locks to clear..."
132+
sleep 20
133+
134+
echo "Running DSpace database migration..."
135+
docker exec $DNAME /bin/bash -c "cd /dspace/bin && ./dspace database migrate ignored"
136+
137+
echo "Waiting for DSpace to be ready..."
138+
sleep 10
139+
140+
- name: restart dspace container
141+
run: |
142+
export DNAME=dspace${{inputs.INSTANCE}}
143+
echo "Restarting DSpace container..."
144+
docker restart $DNAME
145+
sleep 60
146+
147+
- name: create administrator
148+
run: |
149+
export DNAME=dspace${{inputs.INSTANCE}}
150+
echo "Creating DSpace administrator..."
151+
docker exec $DNAME /bin/bash -c "cd /dspace/bin && ./dspace create-administrator -e dspace.admin.dev@dataquest.sk -f admin -l user -p \"${ADMIN_PASSWORD}\" -c en -o dataquest"
152+
153+
- name: rebuild discovery index and run oai import
154+
run: |
155+
export DNAME=dspace${{inputs.INSTANCE}}
156+
echo "Rebuilding discovery index..."
157+
docker exec $DNAME /bin/bash -c "/dspace/bin/dspace index-discovery -b"
158+
159+
echo "Running OAI import..."
160+
docker exec $DNAME /bin/bash -c "/dspace/bin/dspace oai import -c"

0 commit comments

Comments
 (0)