Files
htwkalender-pwa/.gitlab-ci.yml
2024-04-21 02:38:24 +02:00

197 lines
5.8 KiB
YAML

#Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
#Copyright (C) 2024 HTWKalender support@htwkalender.de
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Affero General Public License for more details.
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <https://www.gnu.org/licenses/>.
stages:
- lint
- build
- test
- oci-build
- deploy
- deploy-dev # New stage for development deployment
lint-frontend:
image: node:lts
stage: lint
rules:
- changes:
- frontend/**/*
script:
- cd frontend
- npm i
- npm run lint-no-fix
lint-backend:
stage: lint
image: golangci/golangci-lint:latest
rules:
- changes:
- backend/**/*
script:
- cd backend
- go mod download
- golangci-lint --version
- golangci-lint run -v --skip-dirs=migrations --timeout=5m
build-backend:
image: golang:alpine
stage: build
rules:
- changes:
- backend/**/*
script:
- cd backend
- go build -o htwkalender
artifacts:
paths:
- backend/htwkalender
- backend/go.sum
- backend/go.mod
build-frontend:
image: node:lts
stage: build
rules:
- changes:
- frontend/**/*
script:
- cd frontend
- npm i
- npm run build
artifacts:
paths:
- frontend/build
test-backend:
image: golang:alpine
stage: test
rules:
- changes:
- backend/**/*
script:
- cd backend
- go test -v ./...
dependencies:
- build-backend
test-frontend:
image: node:lts
stage: test
rules:
- changes:
- frontend/**/*
script:
- cd frontend
- npm i
- npm run test
dependencies:
- lint-frontend
build-backend-image:
stage: oci-build
image: docker:latest
services:
- docker:dind
tags:
- image
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-backend
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "/certs/client"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $IMAGE_TAG -f ./backend/Dockerfile --target prod ./backend
- docker push $IMAGE_TAG
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "development"
changes:
- backend/**/*
build-frontend-image:
stage: oci-build
image: docker:latest
services:
- docker:dind
tags:
- image
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-frontend
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "/certs/client"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- cd ./frontend
script:
- docker build --pull -t $IMAGE_TAG -f ./Dockerfile --target prod .
- docker push $IMAGE_TAG
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "development"
changes:
- frontend/**/*
# Development deployment job
deploy-dev:
stage: deploy-dev # New stage for development deployment
image: alpine:latest
before_script:
- apk add --no-cache openssh-client sed # install dependencies
- eval $(ssh-agent -s) # set some ssh variables
- ssh-add <(echo "$CI_SSH_KEY" | tr -d '\r')
script:
# replace some placeholders
- sed -i -e "s|DOCKER_REGISTRY_REPO|$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG|" docker-compose.dev.yml # Assuming you have a separate docker-compose file for development
# upload necessary files to the dev server
- >
scp -P $CI_SSH_PORT -o StrictHostKeyChecking=no -o LogLevel=ERROR ./docker-compose.dev.yml ./reverseproxy.dev.conf
$CI_SSH_USER@$CI_SSH_DEV_HOST:/home/$CI_SSH_USER/docker/htwkalender/
# ssh to the dev server and start the service
- >
ssh -p $CI_SSH_PORT -o StrictHostKeyChecking=no -o LogLevel=ERROR $CI_SSH_USER@$CI_SSH_DEV_HOST
"cd /home/$CI_SSH_USER/docker/htwkalender/ &&
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY &&
docker compose -f ./docker-compose.dev.yml down && docker compose -f ./docker-compose.dev.yml up -d --remove-orphans && docker logout"
rules:
- if: $CI_COMMIT_BRANCH == "development" # Only execute for the development branch
deploy-all:
stage: deploy
image: alpine:latest
before_script:
- apk add --no-cache openssh-client sed # install dependencies
- eval $(ssh-agent -s) # set some ssh variables
- ssh-add <(echo "$CI_SSH_KEY" | tr -d '\r')
script:
# replace some placeholders
- sed -i -e "s|DOCKER_REGISTRY_REPO|$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG|" docker-compose.prod.yml
# upload necessary files to the server
- >
scp -P $CI_SSH_PORT -o StrictHostKeyChecking=no -o LogLevel=ERROR ./docker-compose.prod.yml ./reverseproxy.conf
$CI_SSH_USER@$CI_SSH_HOST:/home/$CI_SSH_USER/docker/htwkalender/
# ssh to the server and start the service
- >
ssh -p $CI_SSH_PORT -o StrictHostKeyChecking=no -o LogLevel=ERROR $CI_SSH_USER@$CI_SSH_HOST
"cd /home/$CI_SSH_USER/docker/htwkalender/ &&
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY &&
docker compose -f ./docker-compose.prod.yml down && docker compose -f ./docker-compose.prod.yml up -d --remove-orphans && docker logout"
rules:
- if: $CI_COMMIT_BRANCH == "main"