generated from datewu/project-abc
-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (67 loc) · 2.34 KB
/
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
name: Create and publish a Docker image to ghcr.io
on:
push:
tags:
- 'v*.*.*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
docker:
name: build and push image to docker hub
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v3
- name: prepare
id: prep
run: |
DOCKER_IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
#if [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
#fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=current_time::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=git_description::$(git describe --always --dirty --tags --long)
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: buil and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: ./deploy/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
current_time=${{ steps.prep.outputs.current_time }}
git_description=${{ steps.prep.outputs.git_description }}
- name: imge digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: post to set-img webhook
shell: bash
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: ${{ secrets.SET_IMG_URL }}
run: |
curl $URL \
-X POST \
-H "Authorization: $TOKEN" \
--data-binary '{"namespace":"wu","kind": "deploy","name":"set-img","container_name":"img","img":"${{ steps.prep.outputs.tags }}"}'