diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17f1003475cfc4a023ceb5e2ccebe1957eeb2f90..a1fb0cb6c3cd236a4d02ed7a50400bac5d3c10ac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,10 @@ +--- +stages: + - test + - build + - deploy + + .docker: stage: build image: docker:26 @@ -8,8 +15,9 @@ before_script: - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY -.docker-compose-base: +.deploy: image: alpine:latest + stage: deploy before_script: - mkdir $HOME/.ssh - chmod 700 $HOME/.ssh @@ -21,21 +29,14 @@ - apk add --update --no-cache openssh rsync .docker-compose-deploy: - extends: .docker-compose-base + extends: .deploy script: - echo "Deploying $CI_PROJECT_NAME to $CI_ENVIRONMENT_NAME" - | ssh $SSH_USER@$DEPLOYMENT_HOST /bin/bash -s << EOT - set -eu - mkdir -p $DEPLOYMENT_PATH cd $DEPLOYMENT_PATH - if [ ! -d .git ]; then - git init - git remote add origin git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git - else - git remote set-url origin git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git - fi - git fetch origin + git stash + git fetch git checkout ${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}} EOT - | @@ -54,7 +55,7 @@ EOT .docker-compose-recreate: - extends: .docker-compose-base + extends: .deploy script: - echo "Recreating stack on $DEPLOYMENT_HOST" - | @@ -65,7 +66,7 @@ EOT check: - stage: build + stage: test image: node:23-alpine script: - cd app @@ -93,7 +94,6 @@ docker-build-image-tag: - if: '$CI_COMMIT_BRANCH == "main"' deploy-stack:staging: - stage: deploy extends: .docker-compose-deploy needs: ["docker-build-image-tag"] when: manual @@ -105,7 +105,6 @@ deploy-stack:staging: url: $URL recreate-stack:staging: - stage: deploy extends: .docker-compose-recreate needs: ["deploy-stack:staging"] when: manual @@ -117,7 +116,6 @@ recreate-stack:staging: url: $URL deploy-stack:production: - stage: deploy extends: .docker-compose-deploy needs: ["docker-build-image-tag"] when: manual @@ -128,7 +126,6 @@ deploy-stack:production: url: $URL recreate-stack:production: - stage: deploy extends: .docker-compose-recreate needs: ["deploy-stack:production"] when: manual