From: Petr Štetiar Date: Tue, 2 Mar 2021 12:39:19 +0000 (+0100) Subject: GitLab CI integration X-Git-Tag: v1~38 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=70883902ecf13135ab83b2a0410efb6e9209b451;p=buildbot.git GitLab CI integration For improved automation, further QA etc. Signed-off-by: Petr Štetiar --- diff --git a/.gitignore b/.gitignore index 0c3bc5d..5dca1da 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 0000000..df2d17b --- /dev/null +++ b/.gitlab-ci.yml @@ -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 index 0000000..501519b --- /dev/null +++ b/.gitlab/docker.yml @@ -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 index 0000000..a8aef0a --- /dev/null +++ b/.gitlab/docker/README.md @@ -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 index 0000000..10460c6 --- /dev/null +++ b/.gitlab/docker/buildmaster/gitlab.yml @@ -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 index 0000000..960ee25 --- /dev/null +++ b/.gitlab/docker/buildslave/gitlab.yml @@ -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"]