Skip to content
Snippets Groups Projects
Commit f5748e09 authored by dario.genga's avatar dario.genga
Browse files

feat: update .gitlab-ci

parent dcbf99cb
No related branches found
No related tags found
No related merge requests found
# Example of basic pipeline triggered on commit to the main branch. We assume
# to use a minimalistic Alpine Linux Docker image.
---
variables:
# PRODUCTION_IP: "<production-server-IP>"
APP_PAGE: "public/index.html"
CLONE_URL_SSH: "ssh://git@ssh.hesge.ch:${CI_PROJECT_ID}"
CLONE_URL_TOK: "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitedu.hesge.ch"
stages:
- test
# - test
- deploy
default:
# Commmon to all stages -- needed because the image's storage is not persistent across them
before_script:
# uncomment for debugging. Watch out! It *will* expose any secret passed from an unprotected variable.
# - export
- apk -U add git openssh-client rsync
- mkdir -p -m 0700 ~/.ssh
- touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
- git config --global user.email "deployer@ci-cd.lab"
- git config --global user.name "The Deployer"
- apk update
- apk add openssh-client rsync
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir ~/.ssh
# ssh-keyscan -t ecdsa-sha2-nistp256 86.119.42.85
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
unit_test1:
stage: test
script:
- echo "This job shall test that the version string in '${APP_PAGE}' is well formatted"
- git clone --depth=1 ${CLONE_URL_TOK}/${CI_PROJECT_PATH}
- '[[ $(sed -nr "/^\s*Version:\s+([[:digit:]]\.){2}[[:digit:]]\s*\$/p" ${CI_PROJECT_NAME}/${APP_PAGE} | wc -l) -eq 1 ]]
|| { echo "[error] Version string badly formatted or not found"; exit 1; }'
# unit_test1:
# stage: test
# script:
# - git clone $CI_REPOSITORY_URL # Clone our repo locally
# - app_version=$(<app_version_file) # Read the app version number from a file
# - if [ "$app_version" != "expected_version" ]; then exit 1; fi # Check the app version and exit if wrong
deploy_prod:
stage: deploy
......@@ -41,6 +27,6 @@ deploy_prod:
url: http://${PRODUCTION_IP}
script:
- echo "Deploying from ${CI_REPOSITORY_URL}::${CI_COMMIT_REF_NAME}"
- rsync --rsync-path="sudo rsync" -Cavh ${CI_PROJECT_DIR}/public/ ${SSH_USER}@${PRODUCTION_IP}:${WEB_ROOT}
- rsync -rav --delete-after --progress ./public/* terraform@"$PRODUCTION_IP":/usr/share/nginx/html
only:
- main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment