-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (51 loc) · 1.49 KB
/
ci.yaml
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
name: CI - Build and Push Docker Image
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Repository to lowercase
env:
REPOSITORY: ${{ github.repository }}
run: |
echo "IMAGE_NAME=ghcr.io/${REPOSITORY@L}" >> "$GITHUB_ENV"
- name: Gather tags name
env:
IMAGE_NAME: ${{ env.IMAGE_NAME }}
SHA: ${{ github.sha }}
REF: ${{ github.ref }}
id: tags
run: |
RESULT="$IMAGE_NAME:latest,$IMAGE_NAME:$SHA"
case "$REF" in
refs/tags/v*)
RESULT="${RESULT},$IMAGE_NAME:${REF#refs/tags/v}"
;;
esac
echo "tags = $RESULT"
echo "tags=$RESULT" >> "$GITHUB_OUTPUT"
- name: Build and Push Docker Image
uses: docker/build-push-action@v3
with:
file: Dockerfile
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max