Skip to content

Commit 451069d

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-2193 (pull request DSpace#3465)
Task/dspace cris 2024 02 x/DSC-2193 Approved-by: Vincenzo Mecca
2 parents 4303b63 + 2f1e656 commit 451069d

21 files changed

Lines changed: 353 additions & 109 deletions

Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# This image will be published as dspace/dspace-angular
22
# See https://github.com/DSpace/dspace-angular/tree/main/docker for usage details
33

4-
FROM docker.io/node:18-alpine
4+
ARG NODE_VERSION=22
5+
ARG DSPACE_VERSION=2024_02_x
6+
ARG DOCKER_REGISTRY=docker.io
57

6-
# Ensure Python and other build tools are available
7-
# These are needed to install some node modules, especially on linux/arm64
8-
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
8+
FROM ${DOCKER_REGISTRY:-docker.io}/4science/dspace-cris-angular-dependencies:${DSPACE_VERSION:-2024_02_x} AS dev
99

1010
WORKDIR /app
1111
ADD . /app/
1212
EXPOSE 4000
1313

14-
# We run yarn install with an increased network timeout (5min) to avoid "ESOCKETTIMEDOUT" errors from hub.docker.com
15-
# See, for example https://github.com/yarnpkg/yarn/issues/5540
16-
RUN yarn install --network-timeout 300000
17-
1814
# When running in dev mode, 4GB of memory is required to build & launch the app.
1915
# This default setting can be overridden as needed in your shell, via an env file or in docker-compose.
2016
# See Docker environment var precedence: https://docs.docker.com/compose/environment-variables/envvars-precedence/
@@ -25,4 +21,4 @@ ENV NODE_OPTIONS="--max_old_space_size=4096"
2521
# NOTE: At this time it is only possible to run Docker container in Production mode
2622
# if you have a public URL. See https://github.com/DSpace/dspace-angular/issues/1485
2723
ENV NODE_ENV=development
28-
CMD yarn serve --host 0.0.0.0
24+
CMD ["yarn", "serve", "--host", "0.0.0.0"]

Dockerfile.build

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM node:20-alpine AS runtime
2+
3+
ENV NODE_ENV=production \
4+
NODE_OPTIONS="--max_old_space_size=4096"
5+
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
6+
RUN mkdir -p /app/source/config
7+
8+
WORKDIR /app/source
9+
COPY dist/ ./dist
10+
RUN ln -s /data/config.prod.yml /app/source/config/config.prod.yml || true
11+
12+
RUN adduser -D -h /home/dspace -s /bin/bash dspace
13+
RUN chown -R dspace:dspace /app/source/
14+
15+
USER dspace
16+
17+
CMD ["node", "dist/server/main"]

Dockerfile.dependencies

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test build:
2+
# docker build -f Dockerfile.dependencies -t 4science/dspace-angular-dependencies:2024_02_x .
3+
4+
# Angular 17 + Node 22 optimized Dockerfile
5+
ARG NODE_VERSION=22
6+
ARG DSPACE_VERSION=2024_02_X
7+
ARG DOCKER_REGISTRY=docker.io
8+
9+
FROM ${DOCKER_REGISTRY:-docker.io}/node:${NODE_VERSION-22}-alpine AS dependencies
10+
11+
# Install build dependencies
12+
RUN apk add --no-cache python3 make g++
13+
14+
WORKDIR /app
15+
16+
# Install dependencies (use npm ci if you have package-lock.json)
17+
COPY package.json yarn.lock ./
18+
RUN yarn install --network-timeout 300000

Dockerfile.dist

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
13
# This image will be published as dspace/dspace-angular:$DSPACE_VERSION-dist
24
# See https://github.com/DSpace/dspace-angular/tree/main/docker for usage details
35

46
# Test build:
57
# docker build -f Dockerfile.dist -t dspace/dspace-angular:dspace-8_x-dist .
68

7-
FROM docker.io/node:18-alpine AS build
9+
# Angular 17 + Node 22 optimized Dockerfile
10+
ARG NODE_VERSION=22
11+
ARG DSPACE_VERSION=2024_02_x
12+
ARG DOCKER_REGISTRY=docker.io
13+
14+
FROM ${DOCKER_REGISTRY:-docker.io}/4science/dspace-cris-angular-dependencies:${DSPACE_VERSION:-2024_02_x} AS build
815

9-
# Ensure Python and other build tools are available
10-
# These are needed to install some node modules, especially on linux/arm64
11-
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
16+
COPY --parents src/** config/** webpack/** docker/dspace-ui.json angular.json server.ts startup-message.ts tsconfig.json tsconfig.app.json tsconfig.server.json tsconfig.spec.json tsconfig.ts-node.json typedoc.json /app/
1217

1318
WORKDIR /app
14-
COPY package.json yarn.lock ./
15-
RUN yarn install --network-timeout 300000
1619

17-
ADD . /app/
20+
# Build Angular app
1821
RUN yarn build:prod
1922

20-
FROM node:18-alpine
21-
RUN npm install --global pm2
23+
# ---- Production image ----
24+
FROM ${DOCKER_REGISTRY:-docker.io}/node:${NODE_VERSION-22}-alpine AS prod
2225

23-
COPY --chown=node:node --from=build /app/dist /app/dist
24-
COPY --chown=node:node config /app/config
25-
COPY --chown=node:node docker/dspace-ui.json /app/dspace-ui.json
26+
# Install pm2 globally and clean npm cache
27+
RUN npm install --global pm2 && npm cache clean --force
2628

2729
WORKDIR /app
30+
31+
# Only copy built files and config
32+
COPY --chown=node:node --from=build /app/dist /app/dist
33+
COPY --chown=node:node --from=build /app/config /app/config
34+
COPY --chown=node:node --from=build /app/docker/dspace-ui.json /app/dspace-ui.json
35+
2836
USER node
2937
ENV NODE_ENV=production
3038
EXPOSE 4000
31-
CMD pm2-runtime start dspace-ui.json --json
39+
40+
CMD ["pm2-runtime", "start", "dspace-ui.json", "--json"]

bitbucket-pipelines.yml

Lines changed: 195 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,216 @@ options:
33

44
definitions:
55
caches:
6-
node-main: ./node_modules
6+
cypress-2024-02-x: ~/.cache/Cypress
7+
node-2024-02-x: ./node_modules
78

89
steps:
10+
- step: &preliminary-operation
11+
name: Preliminary Operation
12+
image: alpine/git:latest
13+
script:
14+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
15+
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{for(i=2;i<NF;i++) printf "%s%s", $i, (i<NF-1?"--":""); print ""}' | tr '[:upper:]' '[:lower:]')
16+
- echo "Using commit hash $HASH_COMMIT"
17+
- git config --global user.email "${BB_USER}"
18+
- git config --global user.name "${BB_EMAIL}"
19+
- git clone https://x-token-auth:${E2E_ACCESS_TOKEN}@${E2E_VALUES_REPO}
20+
- cd e2erunners-values
21+
- sed "s#HASH_COMMIT#${HASH_COMMIT}#g" TPL >> ${HASH_COMMIT}
22+
- sed -i "s#BRANCH_NAME#${BRANCH_NAME}#g" TPL ${HASH_COMMIT}
23+
- git add ${HASH_COMMIT}
24+
- git commit -m "Add configuration for e2e-${HASH_COMMIT}"
25+
- git push
26+
- cd ..
27+
- git clone https://x-token-auth:${HELM_CHARTS_ACCESS_TOKEN}@${HELM_CHARTS_REPO}
28+
- cd helm-charts
29+
- PATH_VALUE=" e2e-$HASH_COMMIT"
30+
- printf " - name:%s\n" "$PATH_VALUE" >> ${E2E_VALUES}
31+
- git add e2e-ingress/values.yaml
32+
- git commit -m "Add ${HASH_COMMIT} to e2e-ingress values"
33+
- git push
34+
- cd ..
35+
36+
- step: &preliminary-operation-backend
37+
name: Preliminary Operation
38+
image: alpine/git:latest
39+
script:
40+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
41+
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
42+
- echo "Using commit hash $HASH_COMMIT"
43+
- git config --global user.email "${BB_USER}"
44+
- git config --global user.name "${BB_EMAIL}"
45+
- git clone https://x-token-auth:${E2ERUNNERS_ACCESS_TOKEN}@${E2E_VALUES_REPO}
46+
- cd e2erunners-values
47+
- sed "s#HASH_COMMIT#${HASH_COMMIT}#g" TPL >> ${HASH_COMMIT}
48+
- sed -i "s#BRANCH_NAME#${BRANCH_NAME}#g" TPL ${HASH_COMMIT}
49+
- git add ${HASH_COMMIT}
50+
- git commit -m "Add configuration for e2e-${HASH_COMMIT}"
51+
- git push
52+
- cd ..
53+
- git clone https://x-token-auth:${HELM_CHARTS_ACCESS_TOKEN}@${HELM_CHARTS_REPO}
54+
- cd helm-charts
55+
- PATH_VALUE=" e2e-$HASH_COMMIT"
56+
- printf " - name:%s\n" "$PATH_VALUE" >> ${E2E_VALUES}
57+
- git add e2e-ingress/values.yaml
58+
- git commit -m "Add ${HASH_COMMIT} to e2e-ingress values"
59+
- git push
60+
- cd ..
61+
62+
- step: &angular-build
63+
name: angular-build
64+
image:
65+
name: cypress/browsers:node-18.20.3-chrome-125.0.6422.141-1-ff-126.0.1-edge-125.0.2535.85-1
66+
run-as-user: 1000
67+
size: 4x
68+
caches:
69+
- node-2024-02-x
70+
script:
71+
- yarn install --frozen-lockfile
72+
- yarn run build:prod:ci
73+
- yarn run build:mirador
74+
artifacts:
75+
- node_modules/**
76+
- dist/**
77+
978
- step: &unittest-code-checks
1079
name: test-code-checks
1180
image:
1281
name: cypress/browsers:node-18.20.3-chrome-125.0.6422.141-1-ff-126.0.1-edge-125.0.2535.85-1
1382
run-as-user: 1000
1483
size: 4x
1584
caches:
16-
- node-main
85+
- node-2024-02-x
1786
script:
18-
- yarn install --frozen-lockfile
19-
- yarn run lint --quiet
87+
- yarn build:lint
88+
- npm run ng-high-memory -- lint --quiet
2089
- yarn run check-circ-deps
21-
- yarn run build:prod:ci
2290
- yarn run test:headless
91+
artifacts:
92+
- .next/**
93+
- .cache/**
94+
- ~/.cache/Cypress
95+
96+
- step: &run-e2e-tests
97+
name: Run E2E test
98+
image:
99+
name: cypress/browsers:node-18.20.3-chrome-125.0.6422.141-1-ff-126.0.1-edge-125.0.2535.85-1
100+
run-as-user: 0
101+
size: 4x
102+
services:
103+
- docker
104+
caches:
105+
- node-2024-02-x
106+
- cypress-2024-02-x
107+
script:
108+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
109+
- echo "Running tests for commit $HASH_COMMIT"
110+
- export DSPACE_REST_HOST=${E2E_RUNNER_HOST}
111+
- export DSPACE_REST_PORT=443
112+
- export DSPACE_REST_NAMESPACE=/e2e-${HASH_COMMIT}/server
113+
- echo "Configured REST endpoint at https://$DSPACE_REST_HOST$DSPACE_REST_NAMESPACE"
114+
- export DSPACE_REST_SSL=true
115+
- export DSPACE_UI_HOST=127.0.0.1
116+
- export DSPACE_UI_PORT=4000
117+
- export DSPACE_CACHE_SERVERSIDE_BOTCACHE_MAX=0
118+
- export DSPACE_CACHE_SERVERSIDE_ANONYMOUSCACHE_MAX=0
119+
- export CYPRESS_BASE_URL=http://127.0.0.1:4000
120+
- export CYPRESS_CACHE_FOLDER=~/.cache/Cypress
121+
- export CHROME_FLAGS="--no-sandbox --disable-dev-shm-usage --disable-gpu"
122+
- export NODE_OPTIONS="--max-old-space-size=4096"
123+
- npx cypress install
124+
- yarn serve:ssr &
125+
- echo "Waiting for server to start..."
126+
- sleep 10
127+
- echo "Running Cypress tests..."
128+
- yarn cypress:run --env chromeFlags="$CHROME_FLAGS"
129+
- echo "Test execution completed"
130+
artifacts:
131+
- cypress/screenshots/**
132+
- cypress/videos/**
133+
134+
- step: &build-and-push
135+
name: Build and Push Docker Image to ECR
136+
size: 4x
137+
image: atlassian/default-image:3
138+
services:
139+
- docker
140+
script:
141+
- echo "Copying dist to Docker context"
142+
- mkdir -p build-context
143+
- cp -r dist config build-context/
144+
- cp Dockerfile.build build-context/Dockerfile
145+
- cd build-context
146+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
147+
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
148+
- docker build -t dspace-angular:${BRANCH_NAME}-${HASH_COMMIT} -t dspace-angular:${BRANCH_NAME}-latest .
149+
- pipe: atlassian/aws-ecr-push-image:2.5.0
150+
variables:
151+
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
152+
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
153+
AWS_DEFAULT_REGION: $AWS_REGION
154+
IMAGE_NAME: dspace-angular
155+
TAGS: "${BRANCH_NAME}-${HASH_COMMIT} ${BRANCH_NAME}-latest"
156+
157+
- step: &deploy-on-dev
158+
name: Deploy on Development environment
159+
image: alpine/git:latest
160+
script:
161+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
162+
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
163+
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
164+
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
165+
- cd dspace-values
166+
- 'sed -i "/^angular:/,/^[^ ]/s/\\(tag: \\).*/\\1${BRANCH_NAME}-${HASH_COMMIT}/" dev/${BRANCH_FILE}'
167+
- git config --global user.email "ci@4science.com"
168+
- git config --global user.name "CI Bot"
169+
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}"
170+
- git push
171+
172+
- step: &deploy-on-staging
173+
name: Deploy on Staging environment
174+
image: alpine/git:latest
175+
script:
176+
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
177+
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
178+
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
179+
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
180+
- cd dspace-values
181+
- 'sed -i "/^angular:/,/^[^ ]/s/\\(tag: \\).*/\\1${BRANCH_NAME}-${HASH_COMMIT}/" staging/${BRANCH_FILE}'
182+
- git config --global user.email "${BB_EMAIL}"
183+
- git config --global user.name "${BB_USER}"
184+
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}"
185+
- git push
23186

24187
pipelines:
188+
custom:
189+
e2e-on-custom-backend:
190+
- step: *preliminary-operation-backend
191+
- step: *angular-build
192+
- parallel: &parallel-run-tests
193+
- step: *unittest-code-checks
194+
- step: *run-e2e-tests
195+
deploy-on-dev:
196+
- step: *angular-build
197+
- step: *build-and-push
198+
- step: *deploy-on-dev
25199
branches:
26-
'main-cris':
27-
- step: *unittest-code-checks
200+
'dspace-cris-2024_02_x':
201+
- step: *preliminary-operation
202+
- step: *angular-build
203+
- parallel: *parallel-run-tests
204+
- step: *build-and-push
205+
- step: *deploy-on-dev
206+
- step: *deploy-on-staging
28207
'prod/**':
29-
- step: *unittest-code-checks
208+
- step: *preliminary-operation
209+
- step: *angular-build
210+
- parallel: *parallel-run-tests
211+
- step: *build-and-push
212+
- step: *deploy-on-dev
213+
- step: *deploy-on-staging
30214
pull-requests:
31215
'**':
32-
- step: *unittest-code-checks
216+
- step: *preliminary-operation
217+
- step: *angular-build
218+
- parallel: *parallel-run-tests

cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ export default defineConfig({
6262
]
6363
},
6464
defaultCommandTimeout: 10000,
65+
requestTimeout: 20000,
6566
});

cypress/e2e/community-create.cy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ beforeEach(() => {
44
});
55

66
it('should show loading component while saving', () => {
7+
cy.intercept('**/sites/**canSubmit**').as('canSubmit');
8+
cy.wait('@canSubmit');
9+
710
const title = 'Test Community Title';
811
cy.get('#title').type(title);
912

cypress/e2e/health-page.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ beforeEach(() => {
1010

1111
describe('Health Page > Status Tab', () => {
1212
it('should pass accessibility tests', () => {
13-
cy.intercept('GET', '/server/actuator/health').as('status');
13+
cy.intercept('GET', '*/server/actuator/health').as('status');
1414
cy.wait('@status');
1515

1616
cy.get('a[data-test="health-page.status-tab"]').click();
@@ -36,7 +36,7 @@ describe('Health Page > Status Tab', () => {
3636

3737
describe('Health Page > Info Tab', () => {
3838
it('should pass accessibility tests', () => {
39-
cy.intercept('GET', '/server/actuator/info').as('info');
39+
cy.intercept('GET', '*/server/actuator/info').as('info');
4040
cy.wait('@info');
4141

4242
cy.get('a[data-test="health-page.info-tab"]').click();

cypress/e2e/login-modal.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const page = {
2525
},
2626
submitLogoutByPressingButton() {
2727
// This is the POST command that will actually log us out
28-
cy.intercept('POST', '/server/api/authn/logout').as('logout');
28+
cy.intercept('POST', '*/server/api/authn/logout').as('logout');
2929
// Click logout button
3030
cy.get('[data-test="logout-button"]').click();
3131
// Wait until above POST command responds before continuing

0 commit comments

Comments
 (0)