diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..62e1140c605a7ebaf2f9811cafd6bfa383fd7fc4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,20 @@ +image: registry-gitlab.pasteur.fr/dsi-tools/docker-images/docker:latest + +services: + - registry-gitlab.pasteur.fr/dsi-tools/docker-images/docker:dind +stages: + - build + +build: + stage: build + script: + - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" registry-gitlab.pasteur.fr + - docker build --pull -f Dockerfile -t "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" . + - docker push "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" + - docker tag "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" + - docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE:latest" + - docker push "$CI_REGISTRY_IMAGE:latest" + - export MY_TIME=`date +"%F-%H%M"` + - docker tag "$CI_REGISTRY_IMAGE:latest" "$CI_REGISTRY_IMAGE:$MY_TIME" + - docker push "$CI_REGISTRY_IMAGE:$MY_TIME" diff --git a/03-gitlab-CI.md b/03-gitlab-CI.md new file mode 100644 index 0000000000000000000000000000000000000000..b46543e4d0712101e9ffb7c95c3a95205b340ca3 --- /dev/null +++ b/03-gitlab-CI.md @@ -0,0 +1,40 @@ +## Problem statement: +- I want to use gitlab to build my docker image and use it with singularity on maestro + +## Assumptions: +- singularity module on maestro (just `module load singularity`) +- gitlab docker registry which is hosting the image built from the Dockerfile + +## Howto +- create/copy/adapt the .gitlab-ci.yml file + +.gitlab-ci.yml +``` +image: registry-gitlab.pasteur.fr/dsi-tools/docker-images/docker:latest + +services: + - registry-gitlab.pasteur.fr/dsi-tools/docker-images/docker:dind +stages: + - build + +build: + stage: build + script: + - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" registry-gitlab.pasteur.fr + - docker build --pull -f Dockerfile -t "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" . + - docker push "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" + - docker tag "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME" "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" + - docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE:latest" + - docker push "$CI_REGISTRY_IMAGE:latest" + - export MY_TIME=`date +"%F-%H%M"` + - docker tag "$CI_REGISTRY_IMAGE:latest" "$CI_REGISTRY_IMAGE:$MY_TIME" + - docker push "$CI_REGISTRY_IMAGE:$MY_TIME" +``` + +## Caveats +- docker registry is rate limited +- gitlab.pasteur.fr is using a proxy cache to avoid hitting the limit +- you can use the campus registry to keep a copy of your OS base image +- the default time limit is 1h, you can change at Settings -> CI/CD -> Timeout +- uploading to the campus registry takes time (10 GB/hour)