From f38ff28f4b94ca39032d2246126e8423be254e8a Mon Sep 17 00:00:00 2001 From: Arnaud Delcasse Date: Tue, 1 Jun 2021 08:04:55 +0200 Subject: [PATCH] Add gitlab-ci --- .gitignore | 1 + .gitlab-ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a48cf0de --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..f16a5838 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +image: docker:18 + +stages: + - build + - push + +before_script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + +Build: + stage: build + script: + - docker pull $CI_REGISTRY_IMAGE:latest || true + - > + docker build + --pull + --build-arg GITLAB_USER=gitlab-ci-token + --build-arg GITLAB_PASS=$CI_JOB_TOKEN + --cache-from $CI_REGISTRY_IMAGE:latest + --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + +Push latest: + variables: + # We are just playing with Docker here. + # We do not need GitLab to clone the source code. + GIT_STRATEGY: none + stage: push + only: + # Only "master" should be tagged "latest" + - master + script: + # Because we have no guarantee that this job will be picked up by the same runner + # that built the image in the previous step, we pull it again locally + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + # Then we tag it "latest" + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest + # Annnd we push it. + - docker push $CI_REGISTRY_IMAGE:latest + + + +# Finally, the goal here is to Docker tag any Git tag +# GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome +Push tag: + variables: + # Again, we do not need the source code here. Just playing with Docker. + GIT_STRATEGY: none + stage: push + only: + # We want this job to be run on tags only. + - tags + script: + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME