GitLab CI integration
authorPetr Štetiar <ynezz@true.cz>
Tue, 2 Mar 2021 12:39:19 +0000 (13:39 +0100)
committerPetr Štetiar <ynezz@true.cz>
Sat, 6 Mar 2021 06:17:57 +0000 (07:17 +0100)
For improved automation, further QA etc.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
.gitignore
.gitlab-ci.yml [new file with mode: 0644]
.gitlab/docker.yml [new file with mode: 0644]
.gitlab/docker/README.md [new file with mode: 0644]
.gitlab/docker/buildmaster/gitlab.yml [new file with mode: 0644]
.gitlab/docker/buildslave/gitlab.yml [new file with mode: 0644]

index 0c3bc5d66e4246d22994524e7e08fafdf97d1b38..5dca1dad03ccef8adfd851d7510c28f1acc70116 100644 (file)
@@ -17,3 +17,7 @@ phase[12]/http.log
 phase[12]/key-build*
 phase[12]/state.sqlite*
 phase[12]/twistd.*
+!.gitlab-ci.yml
+!.gitlab
+!.gitlab/*
+!.gitlab/**/*
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644 (file)
index 0000000..df2d17b
--- /dev/null
@@ -0,0 +1,12 @@
+variables:
+  BUILDBOT_VERSION: 2.10.1
+
+include:
+  - local: .gitlab/docker.yml
+  - local: .gitlab/docker/buildmaster/gitlab.yml
+  - local: .gitlab/docker/buildslave/gitlab.yml
+
+stages:
+  - docker
+  - docker test
+  - docker deploy
diff --git a/.gitlab/docker.yml b/.gitlab/docker.yml
new file mode 100644 (file)
index 0000000..501519b
--- /dev/null
@@ -0,0 +1,34 @@
+.docker in docker:
+  tags:
+    - gce
+  image: docker:19.03.7
+  services:
+    - docker:19.03.7-dind
+  variables:
+    DOCKER_DRIVER: overlay2
+    DOCKER_TLS_CERTDIR: "/certs"
+
+.build Docker image:
+  stage: docker
+  extends: .docker in docker
+  script:
+    - export IMAGE_NAME="$(echo $CI_JOB_NAME | sed 's/build Docker image \(.*\)/\1/')"
+    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+    - docker build --build-arg BUILDBOT_VERSION=$BUILDBOT_VERSION -t "$IMAGE_NAME" -f "docker/$IMAGE_NAME/Dockerfile" .
+    - docker tag "$IMAGE_NAME" "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG"
+    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG"
+
+.deploy Docker image:
+  extends: .docker in docker
+  script:
+    - export IMAGE_NAME="$(echo $CI_JOB_NAME | sed 's/deploy Docker image \(.*\)/\1/')"
+    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG"
+
+    - docker tag "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:latest"
+    - docker tag "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:latest" "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_SHORT_SHA"
+    - docker tag "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:latest" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:latest"
+
+    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:latest"
+    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_SHORT_SHA"
+    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:latest"
diff --git a/.gitlab/docker/README.md b/.gitlab/docker/README.md
new file mode 100644 (file)
index 0000000..a8aef0a
--- /dev/null
@@ -0,0 +1,6 @@
+# Content
+
+This directory contains bits for Docker images used on the GitLab CI.
+
+## buildmaster
+## buildslave
diff --git a/.gitlab/docker/buildmaster/gitlab.yml b/.gitlab/docker/buildmaster/gitlab.yml
new file mode 100644 (file)
index 0000000..10460c6
--- /dev/null
@@ -0,0 +1,20 @@
+build Docker image buildmaster:
+  stage: docker
+  extends: .build Docker image
+
+test Docker image buildmaster:
+  stage: docker test
+  extends: .docker in docker
+  needs: ["build Docker image buildmaster"]
+  script:
+    - export IMAGE_NAME="$(echo $CI_JOB_NAME | sed 's/test Docker image \(.*\)/\1/')"
+    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG"
+    - >
+      docker run --rm "$CI_REGISTRY_IMAGE/$IMAGE_NAME-$BUILDBOT_VERSION:$CI_COMMIT_REF_SLUG" |
+      grep "buildmaster configured in /master"
+
+deploy Docker image buildmaster:
+  stage: docker deploy
+  extends: .deploy Docker image
+  needs: ["test Docker image buildmaster"]
diff --git a/.gitlab/docker/buildslave/gitlab.yml b/.gitlab/docker/buildslave/gitlab.yml
new file mode 100644 (file)
index 0000000..960ee25
--- /dev/null
@@ -0,0 +1,20 @@
+build Docker image buildslave:
+  stage: docker
+  extends: .build Docker image
+
+test Docker image buildslave:
+  stage: docker test
+  extends: .docker in docker
+  needs: ["build Docker image buildslave"]
+  script:
+    - export IMAGE_NAME="$(echo $CI_JOB_NAME | sed 's/test Docker image \(.*\)/\1/')"
+    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG"
+    - >
+      docker run --rm --env BUILDSLAVE_NAME=foo --env BUILDSLAVE_PASSWORD=XXX
+      "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG" | grep "worker configured in /builder"
+
+deploy Docker image buildslave:
+  stage: docker deploy
+  extends: .deploy Docker image
+  needs: ["test Docker image buildslave"]