-
Notifications
You must be signed in to change notification settings - Fork 12
139 lines (126 loc) · 5.85 KB
/
deploy-docker.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: "Deploy Docker Image"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
# run every day at midnight
schedule:
- cron: '0 0 * * *'
push:
branches:
- '*'
- '!dependabot/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# use DOCKERHUB_USERNAME as the name maybe different from the GitHub username
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/arm-dependencies
TAG: latest
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
-
name: Checkout repository
uses: actions/checkout@v4
-
name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
-
name: Set tag for non-default branch
if: ${{ steps.branch-name.outputs.is_default == 'false' && steps.branch-name.outputs.default_branch != '' && github.actor != 'dependabot[bot]' }}
run: |
echo "Run me: (${{ steps.branch-name.outputs.is_default == 'false' && steps.branch-name.outputs.default_branch != '' && github.actor != 'dependabot[bot]' }})"
echo "Set tag for PR: ${{ github.event_name == 'pull_request' || github.actor == 'dependabot[bot]' && steps.branch-name.outputs.is_default == 'false' && steps.branch-name.outputs.default_branch != '' }} "
echo "Actor = ${{ github.actor }}"
echo "event name is ${{ github.event_name }}"
echo "PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')"
echo "PR NAME: ${GITHUB_REF##*/}"
echo "PR number: ${{ github.event.pull_request.number }}"
echo "Branch name is ${{ steps.branch-name.outputs.ref_branch }}"
echo "Main name is ${{ steps.branch-name.outputs.default_branch }}"
echo "TAG=${{ steps.branch-name.outputs.ref_branch }}" >> $GITHUB_ENV
-
name: Set tag for PR
if: ${{ github.event_name == 'pull_request' || github.actor == 'dependabot[bot]' && steps.branch-name.outputs.is_default == 'false' && steps.branch-name.outputs.default_branch != '' }}
run: |
SAFETAG="${{ steps.branch-name.outputs.ref_branch }}"
#echo "Tag will be: pr${SAFETAG%/*}"
echo "Branch name is ${{ steps.branch-name.outputs.ref_branch }}" # 102/merge
echo "Main name is ${{ steps.branch-name.outputs.default_branch }}"
echo "TAG=pr${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "VERSION=pr${GITHUB_REF##*/}" >> $GITHUB_ENV
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
# Workaround: https://github.com/docker/build-push-action/issues/461
-
name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
# Login against all registries
# https://github.com/docker/login-action
-
name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
-
name: Extract Docker metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
-
name: Set Version number
run: |
if [ ${{ steps.branch-name.outputs.is_default }} = true ]; then
VER=$(cat VERSION)
echo "VERSION=$VER" >> $GITHUB_ENV
else
echo "VERSION=${{ env.TAG }}" >> $GITHUB_ENV
echo "${{ env.TAG }}" > ./VERSION
fi
-
name: Set build datetime
run: |
TIMESTAMP=$(date -u +'%Y-%m-%d T%H:%M:%SZ')
echo "BUILD_DATE=$TIMESTAMP" >> $GITHUB_ENV
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
-
name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
${{ env.IMAGE_NAME }}:${{ env.TAG }}
${{ env.IMAGE_NAME }}:${{ env.VERSION }}
labels: ${{ steps.meta.outputs.labels }}