docker部署gitlab-runner
要求
在注册runner之前,您必须首先:
- 将其安装在与安装 GitLab 的服务器不同的服务器上
- 获取令牌:
- 对于共享运行器,让管理员转到 GitLab 管理区域并选择Overview > Runners
- 对于group runner,转到CI/CD > Runners
- 对于project runner,转到Settings > CI/CD并展开Runners部分
生成配置文件
# docker run --rm -v /data/apps/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v10.5.0 register \
--non-interactive \
--executor "docker" \
--docker-image alpine:latest \
--url "https://gitlab.com/" \
--registration-token "PROJECT_REGISTRATION_TOKEN" \
--description "docker-runner" \
--tag-list "docker,aws" \
--run-untagged="true" \
--locked="false"
Running in system-mode.
Registering runner... succeeded runner=McMs_ez-
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
docker-compose.yml
version: '3.9'
services:
web:
image: 'gitlab/gitlab-runner:v10.5.0'
restart: always
hostname: 'gitlab-runner'
container_name: gitlab-runner
environment:
TZ: Asia/Shanghai
ports:
- '8093:8093'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '/data/apps/gitlab-runner/config:/etc/gitlab-runner'
networks:
- gitlab
networks:
gitlab:
driver: bridge
gradle打包android
.gitlab-ci.yml
image: androidsdk/android-30
stages:
- build
- deploy
build:
stage: build
script:
- ./gradlew assembleT982jptestDebug
artifacts:
paths:
- app/build/outputs/apk/debug/*.apk
deploy:
stage: deploy
script:
- echo "Configure deployment tools and credentials here"
- echo "Deploy the APK file here"
only:
- master
查看job
Running with gitlab-runner 10.5.0 (80b03db9)
on docker-runner 389bb304
Using Docker executor with image androidsdk/android-30 ...
Pulling docker image androidsdk/android-30 ...
Using docker image sha256:719db0146c623b6e4e706957e9d7ead2fb9a05ec2ea1c61cfc7d18342b33dfef for androidsdk/android-30 ...
Running on runner-389bb304-project-1032-concurrent-0 via gitlab-runner...
Fetching changes...
Removing .gradle/
HEAD is now at 5fa4d19 format
From http://gitlab.com/android/nft
5fa4d19..89f22a5 master -> origin/master
Checking out 89f22a5a as master...
Skipping Git submodules setup
$ ./gradlew assembleDebug
Downloading https://services.gradle.org/distributions/gradle-6.5-bin.zip
.........10%..........20%..........30%..........40%.........50%..........60%..........70%..........80%.........90%..........100%
Welcome to Gradle 6.5!
Here are the highlights of this release:
- Experimental file-system watching
- Improved version ordering
- New samples
For more details see https://docs.gradle.org/6.5/release-notes.html
。。。。。
查看CONTAINER
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
97a36916258e 719db0146c62 "sh -c 'if [ -x /usr…" About a minute ago Up About a minute runner-389bb304-project-1032-concurrent-0-build-4
bf4a07f70429 gitlab/gitlab-runner:v10.5.0 "/usr/bin/dumb-init …" 17 minutes ago Up 17 minutes 0.0.0.0:8093->8093/tcp gitlab-runner
参考文档
https://docs.gitlab.com/runner/install/docker.html