From b75a5c1eeade3ce9977fbc870275f89e82c6fcbe Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 22 Dec 2019 02:53:11 +0000 Subject: [PATCH] ci: add pipeline for publishing CV. The following changes are included in this commit: - add a pipeline for publishing the output CV to the master branch when a change has been committed to the master branch. - split the CI configuration into two files: one for the docker build pipeline and the other for the CV build pipeline. --- .gitignore | 3 ++- .gitlab-ci.yml | 41 +++--------------------------- .gitlab/ci/cv-gitlab-ci.yml | 29 +++++++++++++++++++++ .gitlab/ci/docker-gitlab-ci.yml | 45 +++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 .gitlab/ci/cv-gitlab-ci.yml create mode 100644 .gitlab/ci/docker-gitlab-ci.yml diff --git a/.gitignore b/.gitignore index bfe84b4..2a57d3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -__output/ +__output/* +!__output/cv.pdf tags notes.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d23f93f..dad4c8e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,47 +1,12 @@ --- stages: - test -- build - publish variables: IMAGE_NAME: ${CI_REGISTRY}/${CI_PROJECT_PATH}/cv-builder IMAGE_TAG: ${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA} -services: -- docker:19.03.5-dind - -.use-docker: - image: docker:19.03.5 - -.install-deps: &install-deps -- apk add --no-cache make - -test:docker-image: - extends: .use-docker - script: - - *install-deps - - make image - stage: test - only: - changes: - - docker/Dockerfile - except: - refs: - - master - -publish:docker-image: - extends: .use-docker - before_script: - - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} - after_script: - - docker logout ${CI_REGISTRY} - script: - - *install-deps - - make publish - stage: publish - only: - changes: - - docker/Dockerfile - refs: - - master@dananglin/cv +include: +- local: '/.gitlab/ci/docker-gitlab-ci.yml' +- local: '/.gitlab/ci/cv-gitlab-ci.yml' diff --git a/.gitlab/ci/cv-gitlab-ci.yml b/.gitlab/ci/cv-gitlab-ci.yml new file mode 100644 index 0000000..933b8f3 --- /dev/null +++ b/.gitlab/ci/cv-gitlab-ci.yml @@ -0,0 +1,29 @@ +--- +.use-cv-builder: + image: ${IMAGE_NAME}:master-5fbdaa5a + +publish:cv: + extends: .use-cv-builder + before_script: + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh && chmod 700 ~/.ssh + - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts + - chmod 0400 ~/.ssh/known_hosts + - git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git + - git config --global user.email "${GITLAB_USER_EMAIL}" + - git config --global user.name "${GITLAB_USER_NAME}" + stage: publish + script: + - make + - git checkout master + - git add __output/cv.pdf + - 'git commit -m "auto: update CV."' + - git push origin master + only: + refs: + - master@dananglin/cv + except: + changes: + - docker/Dockerfile + - __output/* diff --git a/.gitlab/ci/docker-gitlab-ci.yml b/.gitlab/ci/docker-gitlab-ci.yml new file mode 100644 index 0000000..c737a1d --- /dev/null +++ b/.gitlab/ci/docker-gitlab-ci.yml @@ -0,0 +1,45 @@ +--- +.docker-dind-service: + services: + - docker:19.03.5-dind + +.use-docker: + image: docker:19.03.5 + +.install-deps: &install-deps +- apk add --no-cache make + +test:docker-image: + extends: + - .docker-dind-service + - .use-docker + script: + - *install-deps + - make image + stage: test + only: + refs: + - merge_requests + changes: + - docker/Dockerfile + except: + refs: + - master + +publish:docker-image: + extends: + - .use-docker + - .docker-dind-service + before_script: + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + after_script: + - docker logout ${CI_REGISTRY} + script: + - *install-deps + - make publish + stage: publish + only: + changes: + - docker/Dockerfile + refs: + - master@dananglin/cv