-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (52 loc) · 1.7 KB
/
ci-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
name: Docker
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
docker-build:
name: Build Docker Images
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ vars.GO_VERSION }}
cache-dependency-path: "**/*.sum"
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Shorten hash
id: shorten_hash
run: echo "HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
- name: Lowercase Image Name
run: echo "LOWER_IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build app
run: |
docker build -t ${{ env.LOWER_IMAGE_NAME }}:${{ env.HASH }} -t ${{ env.LOWER_IMAGE_NAME }}:latest .
echo "hash=$hash" >> $GITHUB_ENV
- name: Push app
if: ${{ github.event_name != 'pull_request' }}
run: |
docker push ${{ env.LOWER_IMAGE_NAME }}:$hash
docker push ${{ env.LOWER_IMAGE_NAME }}:latest