Add deployment automation
* Introduce `docker-compose.yml` for containerized service orchestration. * Update `.gitlab-ci.yml` with new deployment stages and sync mechanisms, including production and dev environments.
This commit is contained in:
@@ -23,3 +23,52 @@
|
|||||||
script:
|
script:
|
||||||
- docker build --build-arg WORKDIR_PATH=$WORKDIR_PATH -t $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG -f Dockerfile .
|
- docker build --build-arg WORKDIR_PATH=$WORKDIR_PATH -t $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG -f Dockerfile .
|
||||||
- docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG
|
- docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG
|
||||||
|
|
||||||
|
# Deployment
|
||||||
|
.install-deploy-key: &install-deploy-key
|
||||||
|
- |
|
||||||
|
echo "Installing SSH deploy key..."
|
||||||
|
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$DEPLOY_KEY_BASE64" | base64 -d > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
eval "$(ssh-agent -s)"
|
||||||
|
ssh-add ~/.ssh/deploy_key
|
||||||
|
if [[ "$TAG" == "dev" || "$TAG" == "pipeline" ]]; then
|
||||||
|
HOST="$DEPLOY_DEV_HOST"
|
||||||
|
PORT="${DEPLOY_DEV_PORT:-22}"
|
||||||
|
else
|
||||||
|
HOST="$DEPLOY_PROD_HOST"
|
||||||
|
PORT="${DEPLOY_PROD_PORT:-22}"
|
||||||
|
fi
|
||||||
|
echo "Scanning SSH host $HOST on port $PORT"
|
||||||
|
ssh-keyscan -p "$PORT" "$HOST" >> ~/.ssh/known_hosts || true
|
||||||
|
|
||||||
|
.deploy-template:
|
||||||
|
stage: deploy
|
||||||
|
image: docker:20.10@sha256:2967f0819c84dd589ed0a023b9d25dcfe7a3c123d5bf784ffbb77edf55335f0c
|
||||||
|
before_script:
|
||||||
|
- !reference [ .install-deploy-key ]
|
||||||
|
script: |
|
||||||
|
if [[ "$TAG" == "dev" || "$TAG" == "pipeline" ]]; then
|
||||||
|
HOST="$DEPLOY_DEV_HOST"
|
||||||
|
PORT="${DEPLOY_DEV_PORT:-22}"
|
||||||
|
else
|
||||||
|
HOST="$DEPLOY_PROD_HOST"
|
||||||
|
PORT="${DEPLOY_PROD_PORT:-22}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Copying docker-compose.yml to $HOST:$REMOTE_ENV_PATH/docker-compose.yml"
|
||||||
|
# Ensure remote path exists before scp
|
||||||
|
ssh -p "$PORT" "$DEPLOY_USER@$HOST" "mkdir -p $REMOTE_ENV_PATH"
|
||||||
|
scp -P "$PORT" docker-compose.generated.yml "$DEPLOY_USER@$HOST:$REMOTE_ENV_PATH/docker-compose.yml"
|
||||||
|
|
||||||
|
echo "Deploying DEMO on $HOST"
|
||||||
|
ssh -p "$PORT" "$DEPLOY_USER@$HOST" "
|
||||||
|
cd $REMOTE_ENV_PATH
|
||||||
|
echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
|
||||||
|
docker compose down || true
|
||||||
|
docker compose pull || true
|
||||||
|
docker compose up -d
|
||||||
|
"
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ image: docker:20.10@sha256:2967f0819c84dd589ed0a023b9d25dcfe7a3c123d5bf784ffbb77
|
|||||||
|
|
||||||
include:
|
include:
|
||||||
- local: '.gitlab-ci-template.yml'
|
- local: '.gitlab-ci-template.yml'
|
||||||
|
- local: 'main-website/.gitlab-ci.yml'
|
||||||
- local: 'lawfirm-demos/.gitlab-ci.yml'
|
- local: 'lawfirm-demos/.gitlab-ci.yml'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- dockerize
|
- dockerize
|
||||||
|
- deploy
|
||||||
|
- sync
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
CI_REGISTRY_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH
|
CI_REGISTRY_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH
|
||||||
@@ -20,21 +23,37 @@ cache:
|
|||||||
- node_modules/
|
- node_modules/
|
||||||
- .next/cache/
|
- .next/cache/
|
||||||
|
|
||||||
# Main Website - Build
|
.deploy_production_rule: &deploy_production_rule
|
||||||
build_main:
|
- if: $CI_COMMIT_BRANCH == "production"
|
||||||
stage: build
|
when: manual
|
||||||
extends: .build-next-template
|
allow_failure: true
|
||||||
variables:
|
|
||||||
WORKDIR_PATH: main-website
|
|
||||||
|
|
||||||
# Main Website - Dockerize
|
sync_dev_branch:
|
||||||
docker_main:
|
stage: sync
|
||||||
stage: dockerize
|
image: node:22@sha256:f6b9c31ace05502dd98ef777aaa20464362435dcc5e312b0e213121dcf7d8b95
|
||||||
extends: .docker-build-template
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == "production"'
|
||||||
|
before_script:
|
||||||
|
- git config --global user.email "gitlab-ci@rhein-software.dev"
|
||||||
|
- git config --global user.name "GitLab CI"
|
||||||
|
script:
|
||||||
|
- git remote set-url origin "https://oauth2:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
|
||||||
|
- git checkout dev
|
||||||
|
- git pull origin dev
|
||||||
|
- git merge --no-ff origin/production
|
||||||
|
- git push origin dev
|
||||||
|
|
||||||
|
deploy_dev:
|
||||||
|
extends: .deploy-template
|
||||||
variables:
|
variables:
|
||||||
IMAGE_NAME: main-website
|
TAG: dev
|
||||||
WORKDIR_PATH: main-website
|
REMOTE_ENV_PATH: /opt/rheinsw-demo
|
||||||
DOCKERFILE_PATH: Dockerfile
|
rules:
|
||||||
needs:
|
- if: '$CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "pipeline"'
|
||||||
- job: build_main
|
|
||||||
artifacts: true
|
deploy_prod:
|
||||||
|
extends: .deploy-template
|
||||||
|
variables:
|
||||||
|
TAG: production
|
||||||
|
REMOTE_ENV_PATH: /opt/rheinsw-demo
|
||||||
|
rules: *deploy_production_rule
|
||||||
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
gateway:
|
||||||
|
image: registry.boomlab.party/rheinsw/demo-websites/main-website
|
||||||
|
container_name: main-website
|
||||||
|
ports:
|
||||||
|
- "25600:3000"
|
||||||
|
restart: on-failure
|
||||||
|
|
||||||
|
server:
|
||||||
|
image: registry.boomlab.party/rheinsw/demo-websites/ld1
|
||||||
|
container_name: ld1
|
||||||
|
ports:
|
||||||
|
- "25601:8080"
|
||||||
|
restart: on-failure
|
||||||
18
main-website/.gitlab-ci.yml
Normal file
18
main-website/.gitlab-ci.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Main Website - Build
|
||||||
|
build_main:
|
||||||
|
stage: build
|
||||||
|
extends: .build-next-template
|
||||||
|
variables:
|
||||||
|
WORKDIR_PATH: main-website
|
||||||
|
|
||||||
|
# Main Website - Dockerize
|
||||||
|
docker_main:
|
||||||
|
stage: dockerize
|
||||||
|
extends: .docker-build-template
|
||||||
|
variables:
|
||||||
|
IMAGE_NAME: main-website
|
||||||
|
WORKDIR_PATH: main-website
|
||||||
|
DOCKERFILE_PATH: Dockerfile
|
||||||
|
needs:
|
||||||
|
- job: build_main
|
||||||
|
artifacts: true
|
||||||
Reference in New Issue
Block a user