Service Docker Containerized
Feature ID | FEA001 |
Subsystem the feature is part of | Backend |
Responsible person | Developers |
Status | Implemented |
Description
With this feature, we aim to containerize our service docker which means that its dependencies and its configuration are packaged together as a container image.
Restrictions, requirements and use cases related to this feature
ID | Description |
---|---|
Use Case 1 | Adding new features to the Docker container |
FUNC-REQ-C0001 | You have to be able to dockerize the software |
Preliminary user stories
- As a tester, I want to have dockerizations so that I can test the app in the correct environment. #24
- As a Mysticons admin, I want a docker container of the software so that I can add it to our Kubernetes cluster. #17
User interface mock-up
Implementation
Docker was used for containerization. Containers run at our own CSC instance and Team Mysticons Broseidon network.
Architecture for CSC deployment can be seen on Architecture and Design
Frontend
GitLab CI/CD pipeline
We implemented a pipeline that makes a Docker image everytime code is merged to main
# .gitlab-ci.yml
stages:
- build
build:
stage: build
image: node:latest
only:
- main
script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t tukko .
- docker tag tukko:latest gitlab.labranet.jamk.fi:4567/wimma-lab-2023/iotitude/traffic-visualizer
- docker push gitlab.labranet.jamk.fi:4567/wimma-lab-2023/iotitude/traffic-visualizer
tags:
- docker
Dockerfile
For locally building and running the container we use Dockerfile.
FROM node:20-alpine as build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm i
COPY . .
RUN npm run build
# docker build -t tukko:latest .
# docker run -d --name tukko -p 5173:80 tukko:latest
# OR
# npm run prod
FROM nginx:latest
COPY --from=build /app/dist /usr/share/nginx/html
Backend
GitLab CI/CD Pipeline
The same as with the frontend. If there's a merge happening, build image.
stages:
- build
.build:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=true --cache-copy-layers --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$IMAGE_TAG
tags:
- general
build-development:
extends:
- .build
variables:
IMAGE_TAG: $CI_COMMIT_SHA
build-test:
extends:
- .build
variables:
IMAGE_TAG: $CI_COMMIT_SHA
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Docker Compose
Backend uses Docker Compose instead of a Dockerfile.
Three containers are build with this docker-compose -file. - tukko-app (The backend) - tukko-redis (Redis stack) - tukko-archive (MongoDB)
version: '3.8'
services:
tv-api:
depends_on:
- redis-stack
- mongoDB
image: node:alpine
working_dir: /app
container_name: tukko-app
restart: always
env_file:
- .env
- .env.override
ports:
- "3001:3001"
volumes:
- ./dist/:/app/dist
- ./package.json:/app/package.json
- ./package-lock.json:/app/package-lock.json
command: sh -c "npm i --omit-dev && node dist/index.js"
redis-stack:
image: redis/redis-stack:latest
container_name: tukko-redis
restart: always
ports:
- 6379:6379
- 8001:8001
volumes:
- ./redis-stack.conf:/redis-stack.conf
mongoDB:
image: mongo:jammy
container_name: tukko-archive
env_file:
- .env
- .env.override
ports:
- "2717:27017"
Testing / possible acceptance criteria
Testcase | Test source | Responsible |
---|---|---|
Testcase 1 | FUNC-REQ-C0001 | Testers |