-
Notifications
You must be signed in to change notification settings - Fork 3
128 lines (112 loc) · 4.11 KB
/
image-build.yaml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Build and Push Images
on:
workflow_call:
inputs:
repo:
description: "ecr repo"
required: false
default: "matrixone"
type: string
region:
description: "aws region of ecr"
required: false
default: "us-east-1"
type: string
alias:
description: "ecr public repo alias"
required: false
default: "p4n7f8j9"
type: string
secrets:
DOCKERHUB_USERNAME:
description: 'DOCKERHUB_USERNAME'
required: true
DOCKERHUB_TOKEN:
description: 'DOCKERHUB_TOKEN'
required: true
ACR_USERNAME:
description: 'ACR_USERNAME'
required: true
ACR_TOKEN:
description: 'ACR_TOKEN '
required: true
AWS_ROLE:
description: 'AWS_ROLE'
required: false
permissions:
id-token: write
contents: read
jobs:
dockerhub:
environment: ci
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
# # github OIDC https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section
# with:
# role-to-assume: ${{ secrets.AWS_ROLE }}
# aws-region: ${{ inputs.region }}
# - name: Login to Amazon ECR
# id: login-ecr-public
# uses: aws-actions/amazon-ecr-login@v2
# with:
# registry-type: public
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${GITHUB_REPOSITORY#*/}
ACR_DOCKER_IMAGE="registry.cn-shanghai.aliyuncs.com/${DOCKER_IMAGE}"
# ECR_DOCKER_IMAGE="${{ steps.login-ecr-public.outputs.registry }}/${{ inputs.alias }}/${{ inputs.repo }}"
VERSION=nightly-${GITHUB_SHA::8}
# If this is git tag, use the tag name as a docker tag
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
# TAGS="${DOCKER_IMAGE}:${VERSION},${ACR_DOCKER_IMAGE}:${VERSION},${ECR_DOCKER_IMAGE}:${VERSION}"
TAGS="${DOCKER_IMAGE}:${VERSION},${ACR_DOCKER_IMAGE}:${VERSION}"
# If the VERSION looks like a version number, assume that
# this is the most recent version of the image and also
# tag it 'latest'.
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:latest,${ACR_DOCKER_IMAGE}:latest,${ECR_DOCKER_IMAGE}:latest"
TAGS="$TAGS,${DOCKER_IMAGE}:latest,${ACR_DOCKER_IMAGE}:latest"
fi
# Set output parameters.
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
- name: Get image info
run: |
echo "image-tags: ${{ steps.prep.outputs.tags }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Alicloud Container Registry
uses: docker/login-action@v3
with:
registry: registry.cn-shanghai.aliyuncs.com
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_TOKEN }}
- name: Build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./optools/images/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}