-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (105 loc) · 3.64 KB
/
build.yml
File metadata and controls
117 lines (105 loc) · 3.64 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Build Evaluation Function Image
on:
workflow_call:
inputs:
build-file:
type: string
description: "The path to the Dockerfile to build"
required: false
default: "Dockerfile"
build-context:
type: string
description: "The context to use for the Docker build"
required: false
default: "."
build-target:
type: string
description: "The target stage of the image to build"
required: false
build-args:
type: string
description: "The build arguments to pass to the Docker build"
required: false
build-arm:
type: boolean
description: "Enable aarch64 build. If specified, `platforms` takes precedence over `build-arm`."
required: false
default: true
platforms:
type: string
description: "Specify build platforms. Takes precedence over `build-arm`."
required: false
secrets:
build-secrets:
description: "The Docker secrets to use for the build"
required: false
jobs:
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != github.event.repository.default_branch }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
if: inputs.build-arm && github.ref_name == github.event.repository.default_branch
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx (QEMU)
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
type=edge,branch=main
images: |
ghcr.io/${{ github.repository }}
- name: Free up disk space
run: |
echo "Available space before cleanup:"
df -h
# Remove unnecessary software
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
# Clean apt cache
sudo apt-get clean
# Clean Docker
docker system prune -af --volumes
echo "Available space after cleanup:"
df -h
- name: Build and push
uses: docker/build-push-action@v6
with:
file: ${{ inputs.build-file || 'Dockerfile' }}
context: ${{ inputs.build-context || '.'}}
target: ${{ inputs.build-target }}
push: ${{ (github.event_name == 'push' && (github.ref_name == github.event.repository.default_branch || github.ref_type == 'tag')) || github.event_name == 'pull_request' }}
platforms: 'linux/amd64'
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max,ignore-error=true
build-args: ${{ inputs.build-args }}
secrets: ${{ secrets.build-secrets }}