forked from stardew-valley-dedicated-server/server
-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (107 loc) · 4.27 KB
/
build-image.yml
File metadata and controls
117 lines (107 loc) · 4.27 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 Docker Image
on:
workflow_call:
inputs:
image_name:
description: 'Docker image name (e.g., sdvd/server)'
required: true
type: string
context:
description: 'Docker build context path'
required: true
type: string
dockerfile:
description: 'Path to Dockerfile'
required: true
type: string
version:
description: 'Version tag for the image'
required: true
type: string
additional_tag:
description: 'Additional tag (e.g., latest, preview)'
required: false
type: string
default: ''
cache_scope:
description: 'Cache scope for GHA cache (leave empty for default)'
required: false
type: string
default: ''
use_steam_secrets:
description: 'Whether to pass Steam secrets to the build'
required: false
type: boolean
default: false
push:
description: 'Whether to push the image'
required: false
type: boolean
default: true
permissions: {}
jobs:
build:
name: Build ${{ inputs.image_name }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Login to DockerHub
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ${{ inputs.image_name }}
tags: |
type=raw,value=${{ inputs.version }}
${{ inputs.additional_tag != '' && format('type=raw,value={0}', inputs.additional_tag) || '' }}
- name: Build and push Docker image (with Steam secrets)
if: inputs.use_steam_secrets
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true
secrets: |
steam_username=${{ secrets.STEAM_USERNAME }}
steam_password=${{ secrets.STEAM_PASSWORD }}
steam_refresh_token=${{ secrets.STEAM_REFRESH_TOKEN }}
cache-from: ${{ inputs.cache_scope != '' && format('type=gha,scope={0}', inputs.cache_scope) || 'type=gha' }}
cache-to: ${{ inputs.cache_scope != '' && format('type=gha,mode=max,scope={0}', inputs.cache_scope) || 'type=gha,mode=max' }}
- name: Build and push Docker image
if: ${{ !inputs.use_steam_secrets }}
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true
cache-from: ${{ inputs.cache_scope != '' && format('type=gha,scope={0}', inputs.cache_scope) || 'type=gha' }}
cache-to: ${{ inputs.cache_scope != '' && format('type=gha,mode=max,scope={0}', inputs.cache_scope) || 'type=gha,mode=max' }}
- name: Build summary
run: |
echo "### ${{ inputs.image_name }} Build" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Docker Images:**" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ inputs.image_name }}:${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
if [ -n "${{ inputs.additional_tag }}" ]; then
echo "- \`${{ inputs.image_name }}:${{ inputs.additional_tag }}\`" >> $GITHUB_STEP_SUMMARY
fi