Skip to content

Commit 7c961d9

Browse files
KasinhouMatus Kasak
andauthored
JCU/Docker update (#1345)
* Update docker for jcu * Resolve the loadsql problem * Keeping higher versions --------- Co-authored-by: Matus Kasak <matus.kasak@dataquest.sk>
1 parent 821c359 commit 7c961d9

14 files changed

Lines changed: 280 additions & 395 deletions

File tree

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/target/
55
dspace/modules/*/target/
66
Dockerfile.*
7-
dspace/src/main/docker/dspace-postgres-loadsql
7+
dspace/src/main/docker/dspace-postgres-pgcrypto
8+
dspace/src/main/docker/dspace-postgres-pgcrypto-curl
89
dspace/src/main/docker/README.md
910
dspace/src/main/docker-compose/

.github/workflows/build.yml

Lines changed: 8 additions & 5 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-java-with-maven
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)
@@ -81,9 +87,6 @@ jobs:
8187
# Codecov upload is a separate job in order to allow us to restart this separate from the entire build/test
8288
# job above. This is necessary because Codecov uploads seem to randomly fail at times.
8389
# See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
84-
# Codecov upload disabled for the JCU fork: the repository is not configured with a
85-
# CODECOV_TOKEN and the project-level coverage check fails on customization commits.
86-
# Coverage is still produced and uploaded as a build artifact by the 'tests' job above.
8790
# codecov:
8891
# # Must run after 'tests' job above
8992
# needs: tests

.github/workflows/docker.yml

Lines changed: 74 additions & 150 deletions
Large diffs are not rendered by default.

.github/workflows/reusable-docker-build.yml

Lines changed: 30 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ on:
88
workflow_call:
99
# Possible Inputs to this reusable job
1010
inputs:
11+
python_version_script_dest:
12+
required: false
13+
default: version.txt
14+
type: string
15+
run_python_version_script:
16+
required: false
17+
default: false
18+
type: boolean
1119
# Build name/id for this Docker build. Used for digest storage to avoid digest overlap between builds.
1220
build_id:
1321
required: true
@@ -58,9 +66,9 @@ env:
5866
# e.g. PR against 'main' will use "latest". a PR against 'dspace-7_x' will use 'dspace-7_x'.
5967
IMAGE_TAGS: |
6068
type=raw,value=latest,enable=${{ github.ref_name == github.event.repository.default_branch }}
69+
type=raw,value=${{ github.sha }}
6170
type=ref,event=branch,enable=${{ github.ref_name != github.event.repository.default_branch }}
6271
type=ref,event=tag
63-
type=raw,value=${{ (github.event.pull_request.base.ref == github.event.repository.default_branch && 'latest') || github.event.pull_request.base.ref }},enable=${{ github.event_name == 'pull_request' }}
6472
# Define default tag "flavor" for docker/metadata-action per
6573
# https://github.com/docker/metadata-action#flavor-input
6674
# We manage the 'latest' tag ourselves to the 'main' branch (see settings above)
@@ -77,25 +85,27 @@ env:
7785
DEPLOY_ARCH: 'linux/amd64'
7886
# Registry used during building of Docker images. (All images are later copied to docker.io registry)
7987
# We use GitHub's Container Registry to avoid aggressive rate limits at DockerHub.
80-
DOCKER_BUILD_REGISTRY: ghcr.io
88+
DOCKER_BUILD_REGISTRY: docker.io
8189

8290
jobs:
8391
docker-build:
8492

8593
strategy:
8694
matrix:
8795
# Architectures / Platforms for which we will build Docker images
88-
arch: [ 'linux/amd64', 'linux/arm64' ]
96+
# arch: [ 'linux/amd64', 'linux/arm64' ]
97+
arch: [ 'linux/amd64' ]
98+
os: [ ubuntu-latest ]
8999
isPr:
90100
- ${{ github.event_name == 'pull_request' }}
91-
# If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
92-
# The below exclude therefore ensures we do NOT build ARM64 for PRs.
93-
exclude:
94-
- isPr: true
95-
arch: linux/arm64
101+
# If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
102+
# The below exclude therefore ensures we do NOT build ARM64 for PRs.
103+
# exclude:
104+
# - isPr: true
105+
# os: ubuntu-latest
106+
# arch: linux/arm64
96107

97-
# If ARM64, then use the Ubuntu ARM64 runner. Otherwise, use the Ubuntu AMD64 runner
98-
runs-on: ${{ matrix.arch == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
108+
runs-on: ${{ matrix.os }}
99109

100110
steps:
101111
# This step converts the slashes in the "arch" matrix values above into dashes & saves to env.ARCH_NAME
@@ -111,15 +121,21 @@ jobs:
111121
- name: Checkout codebase
112122
uses: actions/checkout@v6
113123

124+
- name: Add version
125+
if: ${{ inputs.run_python_version_script }}
126+
run: python scripts/sourceversion.py ${{ github.server_url }}/${{ github.repository }}/actions/runs/ ${{ github.run_id }} > ${{ inputs.python_version_script_dest }}
127+
128+
114129
# https://github.com/docker/login-action
115130
# NOTE: This login occurs for BOTH non-PRs or PRs. PRs *must* also login to access private images from GHCR
116131
# during the build process
117132
- name: Login to ${{ env.DOCKER_BUILD_REGISTRY }}
133+
# Only login if not a PR, as PRs only trigger a Docker build and not a push
134+
if: ${{ ! matrix.isPr }}
118135
uses: docker/login-action@v4
119136
with:
120-
registry: ${{ env.DOCKER_BUILD_REGISTRY }}
121-
username: ${{ github.repository_owner }}
122-
password: ${{ secrets.GITHUB_TOKEN }}
137+
username: ${{ secrets.DOCKER_USERNAME }}
138+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
123139

124140
# https://github.com/docker/setup-buildx-action
125141
- name: Setup Docker Buildx
@@ -164,193 +180,4 @@ jobs:
164180
# Use GitHub cache to load cached Docker images and cache the results of this build
165181
# This decreases the number of images we need to fetch from DockerHub
166182
cache-from: type=gha,scope=${{ inputs.build_id }}
167-
cache-to: type=gha,scope=${{ inputs.build_id }},mode=min
168-
169-
# Export the digest of Docker build locally
170-
- name: Export Docker build digest
171-
if: ${{ ! matrix.isPr }}
172-
run: |
173-
mkdir -p /tmp/digests
174-
digest="${{ steps.docker_build.outputs.digest }}"
175-
touch "/tmp/digests/${digest#sha256:}"
176-
177-
# Upload digest to an artifact, so that it can be used in combined manifest below
178-
# (The purpose of the combined manifest is to list both amd64 and arm64 builds under same tag)
179-
- name: Upload Docker build digest to artifact
180-
if: ${{ ! matrix.isPr }}
181-
uses: actions/upload-artifact@v7
182-
with:
183-
name: digests-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
184-
path: /tmp/digests/*
185-
if-no-files-found: error
186-
retention-days: 1
187-
188-
#------------------------------------------------------------------------------
189-
# Second, we build the image again in order to store it in a local TAR file.
190-
# This TAR of the image is cached/saved as an artifact, so that it can be used
191-
# by later jobs to install the brand-new images for automated testing.
192-
# This TAR build is performed BOTH for PRs and for branch commits (non-PRs).
193-
#
194-
# (This approach has the advantage of avoiding having to download the newly built
195-
# image from DockerHub or GHCR during automated testing.)
196-
#
197-
# See the 'docker-deploy' job in docker.yml as an example of where this TAR is used.
198-
#-------------------------------------------------------------------------------
199-
# Build local image (again) and store in a TAR file in /tmp directory
200-
# This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
201-
# NOTE: This step cannot be combined with the build above as it's a different type of output.
202-
- name: Build and push image to local TAR file
203-
if: ${{ matrix.arch == 'linux/amd64'}}
204-
uses: docker/build-push-action@v7
205-
with:
206-
build-contexts: |
207-
${{ inputs.dockerfile_additional_contexts }}
208-
context: ${{ inputs.dockerfile_context }}
209-
file: ${{ inputs.dockerfile_path }}
210-
# Tell DSpace's Docker files to use the build registry instead of DockerHub
211-
build-args:
212-
DOCKER_REGISTRY=${{ env.DOCKER_BUILD_REGISTRY }}
213-
platforms: ${{ matrix.arch }}
214-
tags: ${{ steps.meta_build.outputs.tags }}
215-
labels: ${{ steps.meta_build.outputs.labels }}
216-
# Use GitHub cache to load cached Docker images and cache the results of this build
217-
# This decreases the number of images we need to fetch from DockerHub
218-
cache-from: type=gha,scope=${{ inputs.build_id }}
219-
cache-to: type=gha,scope=${{ inputs.build_id }},mode=min
220-
# Export image to a local TAR file
221-
outputs: type=docker,dest=/tmp/${{ inputs.build_id }}.tar
222-
223-
# Upload the local docker image (in TAR file) to a build Artifact
224-
# This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
225-
- name: Upload local image TAR to artifact
226-
if: ${{ matrix.arch == 'linux/amd64'}}
227-
uses: actions/upload-artifact@v7
228-
with:
229-
name: docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
230-
path: /tmp/${{ inputs.build_id }}.tar
231-
if-no-files-found: error
232-
retention-days: 1
233-
234-
##########################################################################################
235-
# Merge Docker digests (from various architectures) into a single manifest.
236-
# This runs after all Docker builds complete above. The purpose is to include all builds
237-
# under a single manifest for this tag.
238-
# (e.g. both linux/amd64 and linux/arm64 should be listed under the same tagged Docker image)
239-
##########################################################################################
240-
docker-build_manifest:
241-
# Only run if this is NOT a PR
242-
if: ${{ github.event_name != 'pull_request' }}
243-
runs-on: ubuntu-latest
244-
needs:
245-
- docker-build
246-
steps:
247-
- name: Download Docker build digests
248-
uses: actions/download-artifact@v8
249-
with:
250-
path: /tmp/digests
251-
# Download digests for both AMD64 and ARM64 into same directory
252-
pattern: digests-${{ inputs.build_id }}-*
253-
merge-multiple: true
254-
255-
- name: Login to ${{ env.DOCKER_BUILD_REGISTRY }}
256-
uses: docker/login-action@v4
257-
with:
258-
registry: ${{ env.DOCKER_BUILD_REGISTRY }}
259-
username: ${{ github.repository_owner }}
260-
password: ${{ secrets.GITHUB_TOKEN }}
261-
262-
- name: Set up Docker Buildx
263-
uses: docker/setup-buildx-action@v4
264-
265-
- name: Add Docker metadata for image
266-
id: meta
267-
uses: docker/metadata-action@v6
268-
with:
269-
images: ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}
270-
tags: ${{ env.IMAGE_TAGS }}
271-
flavor: ${{ env.TAGS_FLAVOR }}
272-
273-
- name: Create manifest list from digests and push to ${{ env.DOCKER_BUILD_REGISTRY }}
274-
working-directory: /tmp/digests
275-
run: |
276-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
277-
$(printf '${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
278-
279-
- name: Inspect manifest in ${{ env.DOCKER_BUILD_REGISTRY }}
280-
run: |
281-
docker buildx imagetools inspect ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
282-
283-
##########################################################################################
284-
# Copy images / manifest to DockerHub.
285-
# This MUST run after *both* images (AMD64 and ARM64) are built and uploaded to GitHub
286-
# Container Registry (GHCR). Attempting to run this in parallel to GHCR builds can result
287-
# in a race condition...i.e. the copy to DockerHub may fail if GHCR image has been updated
288-
# at the moment when the copy occurs.
289-
##########################################################################################
290-
docker-copy_to_dockerhub:
291-
# Only run if this is NOT a PR
292-
if: ${{ github.event_name != 'pull_request' }}
293-
runs-on: ubuntu-latest
294-
needs:
295-
- docker-build_manifest
296-
297-
steps:
298-
# 'regctl' is used to more easily copy the image to DockerHub and obtain the digest from DockerHub
299-
# See https://github.com/regclient/regclient/blob/main/docs/regctl.md
300-
- name: Install regctl for Docker registry tools
301-
run: |
302-
export REGCTL_VERSION=v0.9.2
303-
mkdir -p bin
304-
curl -sSLo bin/regctl https://github.com/regclient/regclient/releases/download/${REGCTL_VERSION}/regctl-linux-amd64
305-
chmod a+x bin/regctl
306-
echo "$(pwd)/bin" >> $GITHUB_PATH
307-
308-
# This recreates Docker tags for DockerHub
309-
- name: Add Docker metadata for image
310-
id: meta_dockerhub
311-
uses: docker/metadata-action@v6
312-
with:
313-
images: ${{ env.IMAGE_NAME }}
314-
tags: ${{ env.IMAGE_TAGS }}
315-
flavor: ${{ env.TAGS_FLAVOR }}
316-
317-
# Login to source registry first, as this is where we are copying *from*
318-
- name: Login to ${{ env.DOCKER_BUILD_REGISTRY }}
319-
uses: docker/login-action@v4
320-
with:
321-
registry: ${{ env.DOCKER_BUILD_REGISTRY }}
322-
username: ${{ github.repository_owner }}
323-
password: ${{ secrets.GITHUB_TOKEN }}
324-
325-
# Login to DockerHub, since this is where we are copying *to*
326-
- name: Login to DockerHub
327-
uses: docker/login-action@v4
328-
with:
329-
username: ${{ secrets.DOCKER_USERNAME }}
330-
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
331-
332-
# Copy the image from source to DockerHub
333-
- name: Copy image from ${{ env.DOCKER_BUILD_REGISTRY }} to docker.io
334-
run: |
335-
regctl image copy ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta_dockerhub.outputs.version }} docker.io/${{ env.IMAGE_NAME }}:${{ steps.meta_dockerhub.outputs.version }}
336-
337-
#--------------------------------------------------------------------
338-
# Finally, check whether demo.dspace.org or sandbox.dspace.org need
339-
# to be redeployed based on these new DockerHub images.
340-
#--------------------------------------------------------------------
341-
# If this build is for the branch that Sandbox uses and passed in a REDEPLOY_SANDBOX_URL secret,
342-
# Then redeploy https://sandbox.dspace.org
343-
- name: Redeploy sandbox.dspace.org (based on main branch)
344-
if: |
345-
env.REDEPLOY_SANDBOX_URL != '' &&
346-
github.ref_name == env.DEPLOY_SANDBOX_BRANCH
347-
run: |
348-
curl -X POST $REDEPLOY_SANDBOX_URL
349-
# If this build is for the branch that Demo uses and passed in a REDEPLOY_DEMO_URL secret,
350-
# Then redeploy https://demo.dspace.org
351-
- name: Redeploy demo.dspace.org (based on maintenance branch)
352-
if: |
353-
env.REDEPLOY_DEMO_URL != '' &&
354-
github.ref_name == env.DEPLOY_DEMO_BRANCH
355-
run: |
356-
curl -X POST $REDEPLOY_DEMO_URL
183+
cache-to: type=gha,scope=${{ inputs.build_id }},mode=max

.github/workflows/tag-release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
workflow_dispatch:
8+
9+
10+
env:
11+
IMAGE_BASE_NAME: dataquest/dspace
12+
13+
jobs:
14+
retag-BE-image:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Login to DockerHub
18+
uses: docker/login-action@v4
19+
with:
20+
username: ${{ secrets.DOCKER_USERNAME }}
21+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
22+
23+
- name: retag image
24+
run: |
25+
docker pull ${{ env.IMAGE_BASE_NAME }}:${{ github.sha }}
26+
docker tag ${{ env.IMAGE_BASE_NAME }}:${{ github.sha }} ${{ env.IMAGE_BASE_NAME }}:${{ github.ref_name }}
27+
28+
docker pull ${{ env.IMAGE_BASE_NAME }}-cli:${{ github.sha }}
29+
docker tag ${{ env.IMAGE_BASE_NAME }}-cli:${{ github.sha }} ${{ env.IMAGE_BASE_NAME }}-cli:${{ github.ref_name }}
30+
31+
docker pull ${{ env.IMAGE_BASE_NAME }}-solr:${{ github.sha }}
32+
docker tag ${{ env.IMAGE_BASE_NAME }}-solr:${{ github.sha }} ${{ env.IMAGE_BASE_NAME }}-solr:${{ github.ref_name }}
33+
34+
docker pull ${{ env.IMAGE_BASE_NAME }}-postgres-pgcrypto:${{ github.sha }}
35+
docker tag ${{ env.IMAGE_BASE_NAME }}-postgres-pgcrypto:${{ github.sha }} ${{ env.IMAGE_BASE_NAME }}-postgres-pgcrypto:${{ github.ref_name }}
36+
37+
docker pull ${{ env.IMAGE_BASE_NAME }}-dependencies:${{ github.sha }}
38+
docker tag ${{ env.IMAGE_BASE_NAME }}-dependencies:${{ github.sha }} ${{ env.IMAGE_BASE_NAME }}-dependencies:${{ github.ref_name }}
39+
40+
- name: push image
41+
run: |
42+
docker push ${{ env.IMAGE_BASE_NAME }}:${{ github.ref_name }}
43+
docker push ${{ env.IMAGE_BASE_NAME }}-cli:${{ github.ref_name }}
44+
docker push ${{ env.IMAGE_BASE_NAME }}-solr:${{ github.ref_name }}
45+
docker push ${{ env.IMAGE_BASE_NAME }}-postgres-pgcrypto:${{ github.ref_name }}
46+
docker push ${{ env.IMAGE_BASE_NAME }}-dependencies:${{ github.ref_name }}

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,12 @@ RUN apt-get update \
6767
EXPOSE 8080 8000
6868
# Give java extra memory (2GB)
6969
ENV JAVA_OPTS=-Xmx2000m
70+
71+
# We create a 'dspace' user to run DSpace instead of running as root. An explicit UID is required
72+
# because Kubernetes deployment accepts only numeric user IDs when specifying the container user.
73+
RUN useradd -u 1100 -m -s /bin/bash dspace \
74+
&& chown -Rv dspace: /dspace
75+
USER dspace
76+
7077
# On startup, run DSpace Runnable JAR (uses the "dspace.dir" setting defined in "dspace__P__dir" env variable)
7178
ENTRYPOINT ["java", "-jar", "webapps/server-boot.jar"]

dspace/src/main/docker-compose/db.entities.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
services:
1010
dspacedb:
11-
image: "${DOCKER_REGISTRY:-docker.io}/${DOCKER_OWNER:-dspace}/dspace-postgres-loadsql:${DSPACE_VER:-dspace-9_x}"
11+
image: dataquest/dspace-postgres-pgcrypto:${DSPACE_VER:-dspace-9_x}-loadsql
1212
environment:
1313
# This SQL is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data
14-
- LOADSQL=${LOADSQL:-https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/dspace7-entities-data.sql}
14+
- LOADSQL=https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/dspace7-entities-data.sql
1515
dspace:
1616
### OVERRIDE default 'entrypoint' in 'docker-compose.yml ####
1717
# Ensure that the database is ready BEFORE starting tomcat
@@ -24,4 +24,4 @@ services:
2424
- |
2525
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
2626
/dspace/bin/dspace database migrate ignored
27-
java -jar /dspace/webapps/server-boot.jar
27+
java -jar /dspace/webapps/server-boot.jar --dspace.dir=/dspace

0 commit comments

Comments
 (0)