未分类
gitlab pipeline 自动构建
使用gitlab pipeline自动构建,需要为项目配置runner, 安装方法为:
1 2 3 4 5 6 7 8 |
curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64" curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm64" chmod +x /usr/local/bin/gitlab-runner useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner gitlab-runner start gitlab-runner register # 按照提示输入相关信息 |
构建一个docker:buildx镜像做测试 .gitlab-ci.yml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
variables: IMAGE_REPO: $REGISTRY/library/docker IMAGE_TAG: buildx before_script: - docker login -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD $REGISTRY build: image: docker:latest stage: build services: - name: docker:dind script: - docker build -t $IMAGE_REPO:$IMAGE_TAG -t $IMAGE_REPO . - docker push $IMAGE_REPO - docker push $IMAGE_REPO:$IMAGE_TAG only: - master |
Dockerfile:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
FROM docker:latest ARG ALPINE_REPO=mirrors.aliyun.com RUN mkdir -p /root/.docker/cli-plugins \ && wget -qO ~/.docker/cli-plugins/docker-buildx $BASE_URL/extra/buildx-v0.8.2.linux-amd64 \ && wget -qO /usr/local/bin/skopeo $BASE_URL/extra/skopeo-linux-amd64 \ && ln -s /usr/local/bin/skopeo /usr/bin/skopeo \ && wget -qO /usr/local/bin/yq $BASE_URL/extra/yq-linux-amd64 \ && chmod +x /root/.docker/cli-plugins/docker-buildx /usr/local/bin/* \ && [[ ! -z $ALPINE_REPO ]] && sed -i "s/dl-cdn.alpinelinux.org/$ALPINE_REPO/" /etc/apk/repositories || true \ && apk --no-cache add wget \ && /bin/rm -rf /tmp/* /var/cache/apk/* |
运行时提示Got permission denied while trying to connect to the Docker daemon socket,解决方法: 在runner服务器上修改gitlab-runner用户加入docker组:
1 |
usermod -a -G docker gitlab-runner |