-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (95 loc) · 3.72 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
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
name: Docker Image CI
on:
push:
branches: [ main, ]
pull_request:
branches: [ main, ]
jobs:
docker:
# runs-on: ubuntu-18.04
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: doublehub
REGISTRY_NAME: oil_price_notify
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.MY_GITHUB_TOKEN }}
# - name: Lower case
# id: string
# uses: ASzc/change-string-case-action@v1
# with:
# string: ${{ env.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
- name: Create Deploy Message
run: |
# Grab the branch path from the appropriate (PR vs. push) property on context
FULL_PATH_REF="${{ github.event.pull_request.head.ref || github.ref }}"
# Strip "refs/heads/" from the start
REF=${FULL_PATH_REF#refs\/heads\/}
# Set it in env
echo "REF=$REF" >> $GITHUB_ENV
# Get the short form of the SHA
SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha || github.sha }})
# Set it in env
echo "SHA=$SHA" >> $GITHUB_ENV
# Yank the commit message from the log, using the SHA
COMMIT_MSG=$(git log -n 1 --format=%s $SHA)
# Set it in env
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV
# If it's a PR, use the title, otherwise, use the commit message
DEPLOY_MESSAGE="${{ github.event.pull_request.title || env.COMMIT_MSG }}"
# Set it in env
echo "DEPLOY_MESSAGE=$DEPLOY_MESSAGE" >> $GITHUB_ENV
# Change all uppercase to lowercase
OWNER=$( echo ${{ github.repository_owner }} | tr '[A-Z]' '[a-z]' )
echo "OWNER=$OWNER" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
# platforms: linux/amd64
push: true
# no-cache: true
tags: |
ghcr.io/${{ env.OWNER }}/${{ env.REGISTRY_NAME }}
${{ env.DOCKERHUB_USERNAME }}/${{ env.REGISTRY_NAME }}
ghcr.io/${{ env.OWNER }}/${{ env.REGISTRY_NAME }}:${{ env.SHA }}
${{ env.DOCKERHUB_USERNAME }}/${{ env.REGISTRY_NAME }}:${{ env.SHA }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: LINE Notify Message
uses: louis70109/[email protected]
with:
token: ${{ secrets.LINE_TOKEN }}
message: |
Commit message: ${{ github.event.head_commit.message }}
Commit URL: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
Status: ${{ job.status }}