Skip to content

Commit

Permalink
Update ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-20tab committed Feb 25, 2023
1 parent e2f5863 commit 9e88651
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
8 changes: 7 additions & 1 deletion {{cookiecutter.project_dirname}}/.env_template
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# consumer
COMPOSE_FILE=docker-compose.yaml:docker-compose/local.yaml
COMPOSE_PROFILES=pact
# CYPRESS_BASE_URL=https://proxy:8443
# INTERNAL_BACKEND_URL=http://provider:8000
# NEXT_PUBLIC_PROJECT_URL=https://localhost:8443
# REACT_ENVIRONMENT=development
# SERVICE_DOCKER_FILE=docker/local.Dockerfile
# cypress
# CYPRESS_BASE_URL=https://proxy:8443
# user
# GROUP_ID=1000
# USER_ID=1000
# USER=appuser
5 changes: 3 additions & 2 deletions {{cookiecutter.project_dirname}}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,20 @@ test:
- docker:20-dind
needs: []
variables:
COMPOSE_FILE: docker-compose.yaml:docker-compose/local.yaml
COMPOSE_FILE: docker-compose.yaml:docker-compose/test.yaml
COMPOSE_PROJECT_NAME: "${CI_PROJECT_PATH_SLUG}-${CI_JOB_NAME}-${CI_JOB_ID}"
SERVICE_CONTAINER_NAME: "${CI_PROJECT_PATH_SLUG}-${CI_JOB_NAME}-${CI_JOB_ID}_frontend"
SERVICE_DOCKER_FILE: "docker/test.Dockerfile"
SERVICE_IMAGE_NAME: "gitlabci_{{ cookiecutter.project_slug }}_{{ cookiecutter.service_slug }}"
SERVICE_IMAGE_TAG: "${CI_JOB_NAME}-${CI_JOB_ID}"
before_script:
- export COMPOSE_FILE=docker-compose/consumer.yaml:docker-compose/volumes.yaml
- mkdir pacts
script:
- docker-compose build --quiet consumer
- docker-compose run --name ${SERVICE_CONTAINER_NAME} consumer
after_script:
- docker cp ${SERVICE_CONTAINER_NAME}:/app/coverage .
- docker cp ${SERVICE_CONTAINER_NAME}:/app/pacts .
- docker-compose down --volumes --remove-orphans
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
Expand Down
5 changes: 5 additions & 0 deletions {{cookiecutter.project_dirname}}/docker-compose/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ services:

consumer:
build:
args:
GROUP_ID: ${GROUP_ID:-1000}
USER_ID: ${USER_ID:-1000}
USER: ${USER:-appuser}
context: ./
dockerfile: ${SERVICE_DOCKER_FILE:-docker/local.Dockerfile}
volumes:
- ./:/app
- /app/node_modules
21 changes: 21 additions & 0 deletions {{cookiecutter.project_dirname}}/docker-compose/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.9"

services:

consumer:
build:
args:
USER: ${USER:-nextjs}
context: ./
dockerfile: ${SERVICE_DOCKER_FILE:-docker/test.Dockerfile}
volumes:
- ./__tests__:/app/__tests__:ro
- ./components:/app/components:ro
- ./declarations:/app/declarations:ro
- ./models:/app/models:ro
- ./pages:/app/pages:ro
- ./public:/app/public:ro
- ./store:/app/store:ro
- ./styles:/app/styles:ro
- ./utils:/app/utils:ro
user: ${USER:-nextjs}
15 changes: 9 additions & 6 deletions {{cookiecutter.project_dirname}}/docker/local.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# syntax=docker/dockerfile:1

FROM node:16-bullseye-slim
ARG DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" WORKDIR=/app
ARG DEBIAN_FRONTEND=noninteractive GROUP_ID=1000 USER_ID=1000 USER=appuser
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 NEXT_TELEMETRY_DISABLED=1 NODE_ENV="development" USER=$USER WORKDIR=/app
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
g++ \
Expand All @@ -11,15 +11,18 @@ RUN apt-get update \
openssh-client \
python3 \
wget \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*
WORKDIR /
COPY --chown=node ./package.json ./
COPY --chown=node ./yarn.lock ./
RUN yarn install
USER node
ENV PATH="/node_modules/.bin:${PATH}"
WORKDIR ${WORKDIR}
RUN chown node ${WORKDIR}
RUN userdel -r node
RUN addgroup --system --gid $GROUP_ID $USER
RUN adduser --system --uid $USER_ID $USER
WORKDIR $WORKDIR
RUN chown $USER_ID:$GROUP_ID $WORKDIR
USER $USER_ID:$GROUP_ID
ENTRYPOINT ["./scripts/entrypoint.sh"]
CMD yarn start
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="frontend" stage="local"
17 changes: 10 additions & 7 deletions {{cookiecutter.project_dirname}}/docker/test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# syntax=docker/dockerfile:1

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

0 comments on commit 9e88651

Please sign in to comment.