-
Notifications
You must be signed in to change notification settings - Fork 7
84 lines (75 loc) · 2.72 KB
/
Copy pathdocker.yml
File metadata and controls
84 lines (75 loc) · 2.72 KB
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
name: Docker
on:
workflow_dispatch:
inputs:
ref:
description: "Git ref or SHA to build"
required: false
default: ""
type: string
push:
branches: [main, staging]
paths:
- Dockerfile
workflow_call:
inputs:
ref:
description: "Git ref or SHA to build"
required: false
default: ""
type: string
permissions:
contents: read
packages: write
jobs:
build-docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 (Node 24)
with:
ref: ${{ inputs.ref != '' && inputs.ref || github.sha }}
- name: Detect Dockerfile
id: detect_dockerfile
run: |
if [ -f Dockerfile ]; then
echo "has_dockerfile=true" >> "$GITHUB_OUTPUT"
else
echo "has_dockerfile=false" >> "$GITHUB_OUTPUT"
fi
- name: Lowercase repository name
if: steps.detect_dockerfile.outputs.has_dockerfile == 'true'
run: echo "REPO=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
- name: Set up Docker Buildx
if: steps.detect_dockerfile.outputs.has_dockerfile == 'true'
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0
- name: Log in to GitHub Container Registry
if: steps.detect_dockerfile.outputs.has_dockerfile == 'true'
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
if: steps.detect_dockerfile.outputs.has_dockerfile == 'true'
id: meta
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
with:
images: ghcr.io/${{ env.REPO }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=staging,enable=${{ github.ref == 'refs/heads/staging' }}
type=ref,event=branch
type=sha
- name: Build and push Docker image
if: steps.detect_dockerfile.outputs.has_dockerfile == 'true'
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max