配置 gitlab-runner
修改配置文件 /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "aws"
url = "http://domain.com/"
id = 17
token = "xxx-xxxxx"
token_obtained_at = 2023-06-06T01:15:31Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
output_limit = 10240
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "docker:20.10.16"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
執行 gitlab-runner restart 重啓生效。
配置項目的 CI
修改配置文件 .gitlab-ci.yml
image: maven:3-jdk-8
cache:
paths:
- target/
before_script:
- echo "$CI_REGISTRY, $CI_BUILD_NAME, $CI_BUILD_REF_NAME, $CI_BUILD_STAGE, $CI_BUILDS_DIR, $CI_PROJECT_PATH, $CI_PIPELINE_ID, $CI_REGISTRY_IMAGE" # debug
stages:
- build
- push
build_artifacts:
stage: build
script: mvn clean package
# artifacts:
# paths:
# - target/*.jar
# expire_in: 1 day
tags:
- aws
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
push_images:
only:
- main
stage: push
image: docker:20.10.16
services:
- name: docker:20.10.16-dind
alias: docker
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
FQ_IMAGE_NAME: "aabb:latest"
AWS_REGION: ap-northeast-1
AWS_REGISTRY: xxxx.dkr.ecr.ap-northeast-1.amazonaws.com
before_script:
- echo $AWS_ACCESS_KEY_ID && echo $AWS_SECRET_ACCESS_KEY
- apk add --no-cache aws-cli
- docker login --username AWS -p $(aws ecr get-login-password --region $AWS_REGION) $AWS_REGISTRY
script:
- docker build -t $FQ_IMAGE_NAME .
- docker tag $FQ_IMAGE_NAME $AWS_REGISTRY/$FQ_IMAGE_NAME
- docker push $AWS_REGISTRY/$FQ_IMAGE_NAME
tags:
- aws