From 1417d7d408fc7b672888ad0857d789a210c1379c Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Mon, 15 Mar 2021 11:12:54 +0000 Subject: [PATCH] ci: after_script should only be used for cleanup - in case of job failure --- .gitlab-ci.yml | 51 +++++++++++++++++++----------- source/_posts/rsync-setup-nixos.md | 16 +++++++--- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0e673b..57113b0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,31 +8,16 @@ variables: NODE_ENV: "production" ## Rename to 'pages' for gitlab pages -test: - stage: test +build: + stage: build before_script: - - apk update && apk add openssh-client git rsync - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts - - chmod 644 ~/.ssh/known_hosts - - echo "$SSH_KEY_1" > ~/.ssh/id_host_1 - - chmod 600 ~/.ssh/id_host_1 - - echo "$SSH_KEY_2" > ~/.ssh/id_host_2 - - chmod 600 ~/.ssh/id_host_2 - - echo "$SSH_CONFIG" > ~/.ssh/config - - chmod 600 ~/.ssh/config + - apk update && apk add git - npm install script: - npm install snyk && npm run snyk # Refer to "scripts" in package.json - npm run build # Generate site - - sh check-homepage.sh # Homepage should exists and non-empty - - after_script: - - rsync -azvh --delete public/ host-1:/var/www/ - - rsync -azvh --delete public/ host-2:/var/www/ rules: # Only trigger through push & "Run pipeline" events in master branch; Skip in renovate job @@ -44,8 +29,36 @@ test: # paths: # - public # deploy from the 'public' folder. -deploy: # Trigger deploy job on curben/curben.gitlab.io +test: + stage: test + + script: + - sh check-homepage.sh # Homepage should exists and non-empty + + rules: + - if: '$RENOVATE != "true" && $CI_COMMIT_REF_NAME == "master" && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "web")' + when: always + +deploy: stage: deploy + + before_script: + - apk update && apk add openssh-client rsync + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + - echo "$SSH_KEY_1" > ~/.ssh/id_host_1 + - chmod 600 ~/.ssh/id_host_1 + - echo "$SSH_KEY_2" > ~/.ssh/id_host_2 + - chmod 600 ~/.ssh/id_host_2 + - echo "$SSH_CONFIG" > ~/.ssh/config + - chmod 600 ~/.ssh/config + + script: + - rsync -azvh --delete public/ host-1:/var/www/ + - rsync -azvh --delete public/ host-2:/var/www/ + trigger: project: curben/curben.gitlab.io branch: master diff --git a/source/_posts/rsync-setup-nixos.md b/source/_posts/rsync-setup-nixos.md index 79eb8dd..746f056 100644 --- a/source/_posts/rsync-setup-nixos.md +++ b/source/_posts/rsync-setup-nixos.md @@ -125,6 +125,18 @@ ssh-keyscan -p 1234 x.x.x.x ``` ``` yml .gitlab-ci.yml +build: + stage: build + + before_script: + - npm install + + script: + - npm run build + +deploy: + stage: deploy + before_script: - apk update && apk add openssh-client rsync - mkdir -p ~/.ssh @@ -136,12 +148,8 @@ ssh-keyscan -p 1234 x.x.x.x - chmod 600 ~/.ssh/id_remote_rsync - echo "$SSH_CONFIG" > ~/.ssh/config - chmod 600 ~/.ssh/config - - npm install script: - - hexo generate # Or `npm run build` - - after_script: ## Dry run - rsync -azvh --delete --dry-run public/ rsync-remote:/var/www/ ## Remove above & uncomment below if no issue