Skip to content

Commit 9e88651

Browse files
committed
Update ci/cd
1 parent e2f5863 commit 9e88651

File tree

7 files changed

+55
-16
lines changed

7 files changed

+55
-16
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
# consumer
12
COMPOSE_FILE=docker-compose.yaml:docker-compose/local.yaml
23
COMPOSE_PROFILES=pact
3-
# CYPRESS_BASE_URL=https://proxy:8443
44
# INTERNAL_BACKEND_URL=http://provider:8000
55
# NEXT_PUBLIC_PROJECT_URL=https://localhost:8443
66
# REACT_ENVIRONMENT=development
77
# SERVICE_DOCKER_FILE=docker/local.Dockerfile
8+
# cypress
9+
# CYPRESS_BASE_URL=https://proxy:8443
10+
# user
11+
# GROUP_ID=1000
12+
# USER_ID=1000
13+
# USER=appuser

{{cookiecutter.project_dirname}}/.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,20 @@ test:
134134
- docker:20-dind
135135
needs: []
136136
variables:
137-
COMPOSE_FILE: docker-compose.yaml:docker-compose/local.yaml
137+
COMPOSE_FILE: docker-compose.yaml:docker-compose/test.yaml
138138
COMPOSE_PROJECT_NAME: "${CI_PROJECT_PATH_SLUG}-${CI_JOB_NAME}-${CI_JOB_ID}"
139139
SERVICE_CONTAINER_NAME: "${CI_PROJECT_PATH_SLUG}-${CI_JOB_NAME}-${CI_JOB_ID}_frontend"
140140
SERVICE_DOCKER_FILE: "docker/test.Dockerfile"
141141
SERVICE_IMAGE_NAME: "gitlabci_{{ cookiecutter.project_slug }}_{{ cookiecutter.service_slug }}"
142142
SERVICE_IMAGE_TAG: "${CI_JOB_NAME}-${CI_JOB_ID}"
143143
before_script:
144-
- export COMPOSE_FILE=docker-compose/consumer.yaml:docker-compose/volumes.yaml
145144
- mkdir pacts
146145
script:
147146
- docker-compose build --quiet consumer
148147
- docker-compose run --name ${SERVICE_CONTAINER_NAME} consumer
149148
after_script:
149+
- docker cp ${SERVICE_CONTAINER_NAME}:/app/coverage .
150+
- docker cp ${SERVICE_CONTAINER_NAME}:/app/pacts .
150151
- docker-compose down --volumes --remove-orphans
151152
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
152153
artifacts:

{{cookiecutter.project_dirname}}/docker-compose/local.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ services:
44

55
consumer:
66
build:
7+
args:
8+
GROUP_ID: ${GROUP_ID:-1000}
9+
USER_ID: ${USER_ID:-1000}
10+
USER: ${USER:-appuser}
711
context: ./
812
dockerfile: ${SERVICE_DOCKER_FILE:-docker/local.Dockerfile}
913
volumes:
1014
- ./:/app
15+
- /app/node_modules
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3.9"
2+
3+
services:
4+
5+
consumer:
6+
build:
7+
args:
8+
USER: ${USER:-nextjs}
9+
context: ./
10+
dockerfile: ${SERVICE_DOCKER_FILE:-docker/test.Dockerfile}
11+
volumes:
12+
- ./__tests__:/app/__tests__:ro
13+
- ./components:/app/components:ro
14+
- ./declarations:/app/declarations:ro
15+
- ./models:/app/models:ro
16+
- ./pages:/app/pages:ro
17+
- ./public:/app/public:ro
18+
- ./store:/app/store:ro
19+
- ./styles:/app/styles:ro
20+
- ./utils:/app/utils:ro
21+
user: ${USER:-nextjs}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# syntax=docker/dockerfile:1
22

33
FROM node:16-bullseye-slim
4-
ARG DEBIAN_FRONTEND=noninteractive
5-
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" WORKDIR=/app
4+
ARG DEBIAN_FRONTEND=noninteractive GROUP_ID=1000 USER_ID=1000 USER=appuser
5+
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" USER=$USER WORKDIR=/app
66
RUN apt-get update \
77
&& apt-get install --assume-yes --no-install-recommends \
88
g++ \
@@ -11,15 +11,18 @@ RUN apt-get update \
1111
openssh-client \
1212
python3 \
1313
wget \
14-
&& rm -rf /var/lib/apt/lists/*
14+
&& rm -rf /var/lib/apt/lists/*
1515
WORKDIR /
1616
COPY --chown=node ./package.json ./
1717
COPY --chown=node ./yarn.lock ./
1818
RUN yarn install
19-
USER node
2019
ENV PATH="/node_modules/.bin:${PATH}"
21-
WORKDIR ${WORKDIR}
22-
RUN chown node ${WORKDIR}
20+
RUN userdel -r node
21+
RUN addgroup --system --gid $GROUP_ID $USER
22+
RUN adduser --system --uid $USER_ID $USER
23+
WORKDIR $WORKDIR
24+
RUN chown $USER_ID:$GROUP_ID $WORKDIR
25+
USER $USER_ID:$GROUP_ID
2326
ENTRYPOINT ["./scripts/entrypoint.sh"]
2427
CMD yarn start
2528
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="frontend" stage="local"
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# syntax=docker/dockerfile:1
22

33
FROM node:16-bullseye-slim
4-
ARG DEBIAN_FRONTEND=noninteractive
5-
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" TZ='Europe/Rome' WORKDIR=/app
4+
ARG DEBIAN_FRONTEND=noninteractive USER=appuser
5+
ENV APPUSER=$USER LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" PATH="$PATH:./node_modules/.bin" TZ='Europe/Rome' WORKDIR=/app
66
RUN apt-get update \
77
&& apt-get install --assume-yes --no-install-recommends \
88
g++ \
99
make \
1010
python3 \
11-
&& rm -rf /var/lib/apt/lists/*
11+
&& rm -rf /var/lib/apt/lists/*
1212
WORKDIR $WORKDIR
13-
ENV PATH="$PATH:./node_modules/.bin"
14-
COPY package.json yarn.lock ./
15-
ENTRYPOINT ["./scripts/test.sh"]
16-
CMD yarn ci:unit-test && yarn ci:contract-test
13+
RUN addgroup --system --gid 1001 $APPUSER
14+
RUN adduser --system --uid 1001 $APPUSER
15+
RUN chown $APPUSER:$APPUSER $WORKDIR
16+
USER $APPUSER
17+
COPY --chown=$APPUSER ./scripts/test.sh jest.config.js middleware.ts next.config.js package.json tsconfig.json yarn.lock ./
18+
ENTRYPOINT ["./test.sh"]
19+
CMD yarn ci:contract-test && yarn ci:unit-test
1720
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="frontend" stage="test"

0 commit comments

Comments
 (0)