From f3c85a545ec9ba6edd53aed9d14575453321fab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20P=C3=A9tr=C3=A9?= <laurent.petre@cern.ch> Date: Tue, 20 Jul 2021 21:17:49 +0200 Subject: [PATCH] Improve GiLab CI pipeline * Use cache for pip during build * Simplify deployment commands * Automatically deploy the master branch --- .gitlab-ci.yml | 36 ++++++++++++++++++++---------------- .gitlab-ci/utils.sh | 20 -------------------- README.md | 12 ++++++------ 3 files changed, 26 insertions(+), 42 deletions(-) delete mode 100644 .gitlab-ci/utils.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d2d4bff..7ba11f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,39 +2,43 @@ stages: - build - deploy -variables: - GIT_DEPTH: 1 - build: - image: python:3 stage: build + variables: + GIT_DEPTH: 1 + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + image: python:3 before_script: - - python3 -m pip install --user -U pip - - python3 -m pip install --user -I -r requirements.txt + - python3 -m venv pyvenv + - source pyvenv/bin/activate + - python3 -m pip install --upgrade pip + - python3 -m pip install -r requirements.txt + - deactivate script: - - python3 -m mkdocs build + - pyvenv/bin/mkdocs build + cache: + paths: + - .cache/pip/ + - pyvenv/ artifacts: expire_in: 1w paths: - site/ deploy: - variables: - HOME: /root stage: deploy - when: manual only: - /^master$/ needs: - build + variables: + GIT_STRATEGY: none before_script: - - source .gitlab-ci/utils.sh - - authenticate_krb + - echo ${SERVICE_ACCOUNT_PASSWORD} | base64 -d | kinit -A -f ${SERVICE_ACCOUNT_USERNAME}@CERN.CH script: - > rsync -av --delete - site/ - ${SERVICE_ACCOUNT_USERNAME}@lxplus.cern.ch:${EOS_SITE_PATH}/ + -e "ssh -o StrictHostKeyChecking=no -o GSSAPIAuthentication=yes -o GSSAPITrustDNS=yes -o GSSAPIDelegateCredentials=yes" + site/ ${SERVICE_ACCOUNT_USERNAME}@lxplus.cern.ch:${EOS_SITE_PATH}/ after_script: - - source .gitlab-ci/utils.sh - - unauthenticate_krb + - kdestroy diff --git a/.gitlab-ci/utils.sh b/.gitlab-ci/utils.sh deleted file mode 100644 index 3980027..0000000 --- a/.gitlab-ci/utils.sh +++ /dev/null @@ -1,20 +0,0 @@ -authenticate_krb () { - local SERVICE_ACCOUNT_PASSWORD=$(echo ${SERVICE_ACCOUNT_PASSWORD} | base64 -d) - echo ${SERVICE_ACCOUNT_PASSWORD} | kinit -A -f ${SERVICE_ACCOUNT_USERNAME}@CERN.CH - - mkdir -p ${HOME}/.ssh - chmod go-rwx -R ${HOME}/.ssh - touch ${HOME}/.ssh/config - chmod go-rw ${HOME}/.ssh/config - cat<<EOF>${HOME}/.ssh/config -HashKnownHosts yes -StrictHostKeyChecking no -GSSAPIAuthentication yes -GSSAPITrustDNS yes -GSSAPIDelegateCredentials yes -EOF -} - -unauthenticate_krb () { - kdestroy -} diff --git a/README.md b/README.md index 5738371..8cbfc79 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ Prepare your environment: ``` bash -$ python3 -m venv pyvenv -$ source pyvenv/bin/activate -$ python3 -m pip install --upgrade pip -$ python3 -m pip install -r requirements.txt -$ deactivate +python3 -m venv pyvenv +source pyvenv/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip install -r requirements.txt +deactivate ``` Start a local web server to visualize your changes: ``` bash -$ pyvenv/bin/mkdocs serve +pyvenv/bin/mkdocs serve ``` -- GitLab