-
Notifications
You must be signed in to change notification settings - Fork 387
70 lines (62 loc) · 2.19 KB
/
docker-image.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
69
70
name: Docker Image CI
on:
workflow_dispatch:
inputs:
image_tag:
description: 'Please input image tag'
required: true
default: ''
env:
ALIYUN_REGISTRY: "${{ secrets.DOCKER_REGISTRY_ALIYUN }}"
ALIYUN_REGISTRY_USER: "${{ secrets.DOCKER_USERNAME_ALIYUN }}"
ALIYUN_REGISTRY_PASSWORD: "${{ secrets.DOCKER_PASSWORD_ALIYUN }}"
jobs:
build_and_push:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: answerhuang/fabulove
- name: Set current timestamp
id: timestamp
run: echo "TIMESTAMP=$(date +%s)" >> $GITHUB_ENV
- name: Set default image tag if not provided
if: ${{ github.event.inputs.image_tag == '' }}
run: echo "IMAGE_TAG=${{ env.TIMESTAMP }}" >> $GITHUB_ENV
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v3
with:
context: .
file: ./docker/Dockerfile
push: true
tags: answerhuang/fabulove:${{ github.event.inputs.image_tag }}
labels: ${{ steps.meta.outputs.labels }}
- name: Rename
id: rename
run: docker tag answerhuang/fabulove:${{ github.event.inputs.image_tag }} $ALIYUN_REGISTRY/great_free/fabulove:${{ github.event.inputs.image_tag }}
- name: Login Aliyun
id: login
run: |
echo $ALIYUN_REGISTRY_USER
echo $ALIYUN_REGISTRY_PASSWORD
echo $ALIYUN_REGISTRY
docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY
- name: Push to Aliyun
id: push_aliyun
run: docker push registry.cn-hangzhou.aliyuncs.com/great_free/fabulove:${{ github.event.inputs.image_tag }}