Skip to content
Snippets Groups Projects
Commit 7e28a935 authored by quentin.fasler's avatar quentin.fasler
Browse files

test

parent 46a4262e
No related branches found
No related tags found
No related merge requests found
variables:
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
- deploy # Uncomment this when youf're ready to use the deploy stage
default:
before_script:
- 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"
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add - # Replace with environment variable for SSH key
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
unit_test1:
stage: test
script:
- echo "This job tests the version string format in '${APP_PAGE}'"
- 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; }'
deploy_prod:
stage: deploy
environment:
name: production
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}
only:
- main
variables: ---
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: stages:
- test # - test
- deploy # Uncomment this when youf're ready to use the deploy stage - deploy
default: default:
before_script: before_script:
- apk -U add git openssh-client rsync - apk update
- mkdir -p -m 0700 ~/.ssh - apk add openssh-client rsync
- 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"
- eval $(ssh-agent -s) - eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add - # Replace with environment variable for SSH key - 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 - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
unit_test1: # unit_test1:
stage: test # stage: test
script: # script:
- echo "This job tests the version string format in '${APP_PAGE}'" # - git clone $CI_REPOSITORY_URL # Clone our repo locally
- git clone --depth=1 ${CLONE_URL_TOK}/${CI_PROJECT_PATH} # - app_version=$(<app_version_file) # Read the app version number from a file
- '[[ $(sed -nr "/^\s*Version:\s+([[:digit:]]\.){2}[[:digit:]]\s*\$/p" ${CI_PROJECT_NAME}/${APP_PAGE} | wc -l) -eq 1 ]] # - if [ "$app_version" != "expected_version" ]; then exit 1; fi # Check the app version and exit if wrong
|| { echo "[error] Version string badly formatted or not found"; exit 1; }'
deploy_prod: deploy_prod:
stage: deploy stage: deploy
...@@ -34,6 +27,6 @@ deploy_prod: ...@@ -34,6 +27,6 @@ deploy_prod:
url: http://${PRODUCTION_IP} url: http://${PRODUCTION_IP}
script: script:
- echo "Deploying from ${CI_REPOSITORY_URL}::${CI_COMMIT_REF_NAME}" - 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: only:
- main - main
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment