Adding GitLab Container Registry Support to cookiecutter-plone-starter

It would be useful to incorporate support for GitLab’s container registry into the cookiecutter-plone-starter project on GitHub.

Not sure how involved this will be, but it looks like a matter of modifying cookiecutter.json and adding a .gitlab-ci.yml file that does some of the work of the github workflows.

At this point, I’m tempted to switch my repo to github to benefit from the out-of-the-box convenience.

Work here like this using a Docker Gitlab CI runner on Linux:

stages:
  - test
  - build
  - tag
  - deploy

variables:
  DOCKER_DRIVER: overlay
  VENV: "off"
  # Change pip's cache directory to be inside the project directory since we can
  # only cache local items.
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG

cache:
  key:
    files:
      - requirements-mxdev.txt
      - constraints-mxdev.txt
    prefix: ${CI_COMMIT_BRANCH}-${CI_JOB_NAME}
  paths:
    - .cache/pip/

testing:
  stage: test
  tags:
  - docker-build
  image: plone/plone-backend:6.0.0
  before_script:
    - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@git.myserver.eu".insteadOf ssh://git@git.myserver.eu
    - make VENV=off VENV_FOLDER=/app install
  script:
    - make VENV=off VENV_FOLDER=/app test

linting:
  stage: test
  tags:
    - docker-build
  image: python:3.11
  before_script:
    - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@git.myserver.eu".insteadOf ssh://git@git.myserver.eu
  script:
    - make lint

build-image:
  image: docker:latest
  needs:
  - testing
  - linting
  only:
  - tags
  tags:
  - docker-build
  services:
  - name: docker:dind
  stage: build
  before_script:
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
  script:
  - echo "build $CI_REGISTRY_IMAGE"
  - docker buildx build --pull -t $IMAGE -t $LATEST .
  - docker push $IMAGE
  - docker push $LATEST

After all I would polish again a bit and it may need some minor modifications, but it works and should be enough to get the idea.

2 Likes