Merge branch 'pipeline-refactoring' into 'dev'

Update CI images with digests and remove redundant declarations

See merge request rheinsw/website!11
This commit is contained in:
2025-03-29 21:30:28 +00:00
parent 6a401bfd63
commit 35d5fa8884

View File

@@ -1,4 +1,4 @@
image: node:20 image: node:20@sha256:735b1ba7e4550c415f98568efbf527e3f75828ac4f10692e490ca78e11d89f6e
workflow: workflow:
rules: rules:
@@ -34,6 +34,23 @@ variables:
- ssh-add ~/.ssh/deploy_key - ssh-add ~/.ssh/deploy_key
- ssh-keyscan -p 22 -H '192.168.41.101' >> ~/.ssh/known_hosts || true - ssh-keyscan -p 22 -H '192.168.41.101' >> ~/.ssh/known_hosts || true
.deploy_production_rule: &deploy_production_rule
- if: $CI_COMMIT_BRANCH == "production"
when: manual
allow_failure: true
.deploy_script: &deploy_script
- |
echo "Deploying $DOCKER_IMAGE:$TAG to $CONTAINER_NAME on port $PORT..."
ssh gitlab@192.168.41.101 -p 22 "
echo \"$CI_REGISTRY_PASSWORD\" | docker login $CI_REGISTRY -u \"$CI_REGISTRY_USER\" --password-stdin &&
docker pull $DOCKER_IMAGE:$TAG &&
docker stop $CONTAINER_NAME || true &&
docker rm $CONTAINER_NAME || true &&
docker run -d --name $CONTAINER_NAME -p $PORT:3000 $DOCKER_IMAGE:$TAG
"
build: build:
stage: build stage: build
script: script:
@@ -43,7 +60,7 @@ build:
dockerize: dockerize:
stage: docker stage: docker
image: docker:latest image: docker:20.10@sha256:2967f0819c84dd589ed0a023b9d25dcfe7a3c123d5bf784ffbb77edf55335f0c
services: services:
- docker:dind - docker:dind
before_script: before_script:
@@ -65,42 +82,29 @@ dockerize:
- dev - dev
- production - production
deploy: deploy_dev:
stage: deploy stage: deploy
image: node:20
before_script: *install_deploy_key before_script: *install_deploy_key
script: script:
- | - TAG="dev"
if [[ "$CI_COMMIT_REF_NAME" == "production" ]]; then - PORT="5100"
TAG="latest" - CONTAINER_NAME="$CI_PROJECT_NAME-dev"
PORT="4100" - *deploy_script
elif [[ "$CI_COMMIT_REF_NAME" == "dev" ]]; then
TAG="dev"
PORT="5100"
else
echo "Skipping deployment for branch $CI_COMMIT_REF_NAME"
exit 0
fi
CONTAINER_NAME="$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME"
echo "Deploying $DOCKER_IMAGE:$TAG to $CONTAINER_NAME on port $PORT..."
ssh gitlab@192.168.41.101 -p 22 "
echo \"$CI_REGISTRY_PASSWORD\" | docker login $CI_REGISTRY -u \"$CI_REGISTRY_USER\" --password-stdin &&
docker pull $DOCKER_IMAGE:$TAG &&
docker stop $CONTAINER_NAME || true &&
docker rm $CONTAINER_NAME || true &&
docker run -d --name $CONTAINER_NAME -p $PORT:3000 $DOCKER_IMAGE:$TAG
"
only: only:
- dev - dev
- production
# ------------------ New sync job added below ------------------ deploy_production:
stage: deploy
rules: *deploy_production_rule
before_script: *install_deploy_key
script:
- TAG="latest"
- PORT="4100"
- CONTAINER_NAME="$CI_PROJECT_NAME-production"
- *deploy_script
sync_branches: sync_branches:
stage: sync stage: sync
image: node:20
rules: rules:
- if: '$CI_COMMIT_BRANCH == "production"' - if: '$CI_COMMIT_BRANCH == "production"'
before_script: before_script: