From d3c11967eb6b592a9165ef5ba2fba702ac59399d Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Tue, 24 May 2022 14:26:26 +0600 Subject: [PATCH 1/5] replace job deploy with remote template --- .gitlab-ci.yml | 83 +++++++------------------------------------------- 1 file changed, 11 insertions(+), 72 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index feed0304..1570ad25 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,79 +2,18 @@ stages: - deploy # Deploy stage -.deploy:theme: - image: ubuntu:focal - stage: deploy - before_script: - - mkdir $HOME/.ssh - - chmod 700 ~/.ssh - # cannot use GitLab variable type File and cp here because key format - # gets garbled somehow; this doesn't happen with echo - - echo "$SSH_PRIVATE_KEY_ED" > $HOME/.ssh/id_ed25519 - - echo "$SSH_PUBKEY_ED" > $HOME/.ssh/id_ed25519.pub - - echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts - - chmod 600 ~/.ssh/id_ed25519 - - chmod 644 ~/.ssh/known_hosts ~/.ssh/id_ed25519.pub - - apt-get update && apt-get install -y openssh-client - script: - - echo "Deploying to $CI_ENVIRONMENT_NAME ($DEPLOYMENT_HOST)" - - ssh $SSH_USER@$DEPLOYMENT_HOST "git clone --depth 1 $CI_REPOSITORY_URL --branch $DEPLOYMENT_BRANCH --single-branch /tmp/${CI_JOB_ID}/eCloud && sudo rsync -avzh --chown www-data:www-data --delete --exclude '.git*' /tmp/${CI_JOB_ID}/eCloud ${DEPLOYMENT_PATH}/html/themes/ && rm -rf /tmp/${CI_JOB_ID} && docker exec -u www-data $CONTAINER_NAME /usr/local/bin/php /var/www/html/occ maintenance:theme:update" +include: + - project: 'e/infra/ecloud/nextcloud-apps/ci-templates' + ref: dev/template + file: 'auto-deploy-pipelines.yml' -deploy:dev01: - extends: .deploy:theme - when: manual - only: - - /^dev\/.*$/ - - master - - main - environment: - name: dev/01 - url: https://dev.eeo.one/ - variables: - DEPLOYMENT_BRANCH: $CI_COMMIT_BRANCH - CONTAINER_NAME: dev01_nextcloud - -deploy:dev02: - extends: .deploy:theme - when: manual - only: - - /^dev\/.*$/ - - master - - main - environment: - name: dev/02 - url: https://ecloud02.dev.eeo.one - variables: - DEPLOYMENT_BRANCH: $CI_COMMIT_BRANCH - CONTAINER_NAME: dev02_nextcloud - -deploy:dev03: - extends: .deploy:theme - when: manual - only: - - /^dev\/.*$/ - - master - - main - environment: - name: dev/03 - url: https://ecloud03.dev.eeo.one - variables: - DEPLOYMENT_BRANCH: $CI_COMMIT_BRANCH - CONTAINER_NAME: dev03_nextcloud - -deploy:staging: - extends: .deploy:theme - when: manual - only: - - master - - main - - production - environment: - name: staging/01 - url: https://eeo.one - variables: - DEPLOYMENT_BRANCH: $CI_COMMIT_BRANCH - CONTAINER_NAME: nextcloud +.deploy:nextcloud-app: + stage: deploy + script: + # overriding script as all it needs is clone, copy and chown + # print var to confirm + - echo "Deploying to $CI_ENVIRONMENT_NAME ($DEPLOYMENT_HOST)" + - ssh $SSH_USER@$DEPLOYMENT_HOST "git clone --depth 1 $CI_REPOSITORY_URL --branch $DEPLOYMENT_BRANCH --single-branch /tmp/${CI_JOB_ID}/eCloud && sudo rsync -avzh --chown www-data:www-data --delete --exclude '.git*' /tmp/${CI_JOB_ID}/eCloud ${DEPLOYMENT_PATH}/html/themes/ && rm -rf /tmp/${CI_JOB_ID} && docker exec -u www-data $CONTAINER_NAME /usr/local/bin/php /var/www/html/occ maintenance:theme:update" deploy:production: extends: .deploy:theme -- GitLab From c7354645ab3c42adb5cce1a5b1fc7a6a56b1890c Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Tue, 24 May 2022 14:32:27 +0600 Subject: [PATCH 2/5] fix extend on prod --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1570ad25..1087aca2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ include: - ssh $SSH_USER@$DEPLOYMENT_HOST "git clone --depth 1 $CI_REPOSITORY_URL --branch $DEPLOYMENT_BRANCH --single-branch /tmp/${CI_JOB_ID}/eCloud && sudo rsync -avzh --chown www-data:www-data --delete --exclude '.git*' /tmp/${CI_JOB_ID}/eCloud ${DEPLOYMENT_PATH}/html/themes/ && rm -rf /tmp/${CI_JOB_ID} && docker exec -u www-data $CONTAINER_NAME /usr/local/bin/php /var/www/html/occ maintenance:theme:update" deploy:production: - extends: .deploy:theme + extends: .deploy:nextcloud-app when: manual only: - production -- GitLab From 9e53bd7cc8bad458dd1c5f3754d9a39d7f5403e6 Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Tue, 24 May 2022 20:17:14 +0600 Subject: [PATCH 3/5] fix file name --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1087aca2..f263e6db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,9 +3,9 @@ stages: # Deploy stage include: - - project: 'e/infra/ecloud/nextcloud-apps/ci-templates' - ref: dev/template - file: 'auto-deploy-pipelines.yml' + - project: "e/infra/ecloud/nextcloud-apps/ci-templates" + ref: dev/template + file: "nc-apps-deploy.yml" .deploy:nextcloud-app: stage: deploy -- GitLab From 959bb760939a11dc87f04bfe8e32185b0c5bc934 Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Wed, 25 May 2022 14:53:12 +0600 Subject: [PATCH 4/5] add checkout deploy --- .gitlab-ci.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f263e6db..54c89e91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,19 +4,15 @@ stages: # Deploy stage include: - project: "e/infra/ecloud/nextcloud-apps/ci-templates" - ref: dev/template - file: "nc-apps-deploy.yml" + ref: dev/nc-apps-checkout-deploy + file: "nc-apps-checkout-deploy.yml" -.deploy:nextcloud-app: - stage: deploy - script: - # overriding script as all it needs is clone, copy and chown - # print var to confirm - - echo "Deploying to $CI_ENVIRONMENT_NAME ($DEPLOYMENT_HOST)" - - ssh $SSH_USER@$DEPLOYMENT_HOST "git clone --depth 1 $CI_REPOSITORY_URL --branch $DEPLOYMENT_BRANCH --single-branch /tmp/${CI_JOB_ID}/eCloud && sudo rsync -avzh --chown www-data:www-data --delete --exclude '.git*' /tmp/${CI_JOB_ID}/eCloud ${DEPLOYMENT_PATH}/html/themes/ && rm -rf /tmp/${CI_JOB_ID} && docker exec -u www-data $CONTAINER_NAME /usr/local/bin/php /var/www/html/occ maintenance:theme:update" +.deploy:nextcloud-app-by-checkout: + stage: deploy + variables: deploy:production: - extends: .deploy:nextcloud-app + extends: .deploy:nextcloud-app-by-checkout when: manual only: - production -- GitLab From 1de2656b4ebd0a2b488cacfd90b79df0518025b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnau=20V=C3=A0zquez?= Date: Wed, 25 May 2022 22:29:55 +0000 Subject: [PATCH 5/5] Override script in template --- .gitlab-ci.yml | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 54c89e91..4c5d0c98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,24 +1,15 @@ -stages: - - deploy +variables: + APP_NAME: eCloud # Deploy stage include: - - project: "e/infra/ecloud/nextcloud-apps/ci-templates" - ref: dev/nc-apps-checkout-deploy - file: "nc-apps-checkout-deploy.yml" + - project: 'e/infra/ecloud/nextcloud-apps/ci-templates' + ref: main + file: 'nc-apps-checkout-deploy.yml' .deploy:nextcloud-app-by-checkout: - stage: deploy - variables: + script: + - ssh $SSH_USER@$DEPLOYMENT_HOST "git clone --depth 1 $CI_REPOSITORY_URL --branch $DEPLOYMENT_BRANCH --single-branch /tmp/${CI_JOB_ID}/${APP_NAME} && sudo rsync -avzh --chown www-data:www-data --delete --exclude '.git*' /tmp/${CI_JOB_ID}/${eCloud} ${DEPLOYMENT_PATH}/html/themes/ && rm -rf /tmp/${CI_JOB_ID} && docker exec -u www-data $CONTAINER_NAME /usr/local/bin/php /var/www/html/occ maintenance:theme:update" + + -deploy:production: - extends: .deploy:nextcloud-app-by-checkout - when: manual - only: - - production - environment: - name: prod/01 - url: https://ecloud.global - variables: - DEPLOYMENT_BRANCH: $CI_COMMIT_BRANCH - CONTAINER_NAME: nextcloud -- GitLab