diff --git a/.gitlab-ci copy.yml b/.gitlab-ci copy.yml new file mode 100644 index 0000000000000000000000000000000000000000..a081d11be447fa86d1460504563218130340b63d --- /dev/null +++ b/.gitlab-ci copy.yml @@ -0,0 +1,39 @@ +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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a081d11be447fa86d1460504563218130340b63d..bec84479c97a90b20102bb46ff6d32956ffa0efd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,31 +1,24 @@ -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 + # - test + - deploy 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" + - apk update + - apk add openssh-client rsync - 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 -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; }' +# 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 @@ -34,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 + - main \ No newline at end of file