-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (44 loc) · 1.78 KB
/
build-image.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
name: Build Velocity Image
concurrency:
group: build-velocity-image-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
types: [closed]
branches: [main]
jobs:
# We are going to build an image and push it to ghcr.io (GitHub Container Registry)
build-final-image:
name: Build Final Image
runs-on: ubuntu-latest
permissions:
packages: write # Needed to push docker image to ghcr.io
contents: read # Needed to read code in repository
steps:
# Docker buildx is useful for caching images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- id: set-var
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository }}
- name: Build and Push Image to ghcr.io
uses: docker/build-push-action@v4
with:
push: true
# Add tags but lowercase the branch name
tags: |
ghcr.io/${{ steps.set-var.outputs.lowercase }}:latest
ghcr.io/${{ steps.set-var.outputs.lowercase }}:${{ github.head_ref }}
cache-from: type=gha # This will use the cached image from the last time we built it (Caching requires buildx done above)
cache-to: type=gha,mode=max # This will cache the image for the next time we build it (max means it will cache all layers)
labels: |
org.opencontainers.image.title=latest
org.opencontainers.image.description=The most recent image built from the main branch
org.opencontainers.image.source=ghcr.io/${{ steps.set-var.outputs.lowercase }}