-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
68 lines (61 loc) · 2 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
stages:
- build-push
- push-manifest
variables:
DOCKER_DRIVER: overlay2
IMAGE_NAME: "aron666/dawn"
TAG_LATEST: "latest"
TAG_VERSION: "1.0.0.13"
BRANCH: main
PROJECT_NAME: "Aron.DawnMiner"
DOCKER_TLS_CERTDIR: "" # 禁用 TLS 驗證
# 定義 Docker login 的全局設置
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
build-amd64:
stage: build-push
tags:
- amd64
image: docker:latest # 使用 Docker 官方鏡像
services:
- docker:dind # 使用 Docker-in-Docker
script:
- cd $PROJECT_NAME
- docker build --build-arg TARGETARCH=amd64 -t $IMAGE_NAME:$CI_COMMIT_SHORT_SHA .
- docker tag $IMAGE_NAME:$CI_COMMIT_SHORT_SHA $IMAGE_NAME:amd64-$TAG_LATEST # 標記為 latest
- docker push $IMAGE_NAME:amd64-$TAG_LATEST
- docker rmi $IMAGE_NAME:$CI_COMMIT_SHORT_SHA $IMAGE_NAME:amd64-$TAG_LATEST
only:
- main # 僅當 main 分支有變更時觸發
build-arm64:
stage: build-push
tags:
- arm64
image: docker:latest
services:
- docker:dind
script:
- cd $PROJECT_NAME
- docker build --build-arg TARGETARCH=arm64 -t $IMAGE_NAME:$CI_COMMIT_SHORT_SHA .
- docker tag $IMAGE_NAME:$CI_COMMIT_SHORT_SHA $IMAGE_NAME:arm64-$TAG_LATEST
- docker push $IMAGE_NAME:arm64-$TAG_LATEST
- docker rmi $IMAGE_NAME:$CI_COMMIT_SHORT_SHA $IMAGE_NAME:arm64-$TAG_LATEST
only:
- main
push-manifest:
stage: push-manifest
tags:
- amd64
image: docker:latest
services:
- docker:dind
script:
- docker pull $IMAGE_NAME:amd64-$TAG_LATEST
- docker pull $IMAGE_NAME:arm64-$TAG_LATEST
- docker manifest create $IMAGE_NAME:$TAG_VERSION $IMAGE_NAME:amd64-$TAG_LATEST $IMAGE_NAME:arm64-$TAG_LATEST
- docker manifest push $IMAGE_NAME:$TAG_VERSION
- docker manifest create $IMAGE_NAME:$TAG_LATEST $IMAGE_NAME:amd64-$TAG_LATEST $IMAGE_NAME:arm64-$TAG_LATEST
- docker manifest push $IMAGE_NAME:$TAG_LATEST
- docker rmi $IMAGE_NAME:amd64-$TAG_LATEST $IMAGE_NAME:arm64-$TAG_LATEST
only:
- main