-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (104 loc) · 3.91 KB
/
Copy pathbuild-docker.yml
File metadata and controls
121 lines (104 loc) · 3.91 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
118
119
120
121
name: Build & Push SteamCMD Server (Docker Hub)
on:
workflow_dispatch:
inputs:
image_name:
description: "Docker Hub image name (e.g., lancommander/counterstrikesource)"
required: true
default: "lancommander/counterstrikesource"
version:
description: "Version tag for the image"
required: true
default: "latest"
push_latest:
description: "Also push the :latest tag"
required: true
type: boolean
default: true
platforms:
description: "Build platforms (comma-separated)"
required: true
default: "linux/amd64"
push:
tags:
- "v*"
permissions:
contents: read
concurrency:
group: dockerhub-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Derive settings from either tag push or workflow_dispatch inputs
- name: Resolve build variables
id: vars
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
# Tag push, e.g. refs/tags/v3339
TAG_NAME="${GITHUB_REF_NAME}"
VERSION="${TAG_NAME#v}"
# Default image name for tag builds:
# Set this to your preferred repo, or replace with a repo secret if you prefer.
IMAGE_NAME="${{ vars.DOCKERHUB_IMAGE_NAME }}"
if [[ -z "${IMAGE_NAME}" ]]; then
echo "DOCKERHUB_IMAGE_NAME variable is not set. Create it (e.g., 'lancommander/counterstrikesource') or use workflow_dispatch."
exit 1
fi
PUSH_LATEST="true"
PLATFORMS="linux/amd64"
else
IMAGE_NAME="${{ inputs.image_name }}"
VERSION="${{ inputs.version }}"
PUSH_LATEST="${{ inputs.push_latest }}"
PLATFORMS="${{ inputs.platforms }}"
fi
echo "image_name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
echo "push_latest=${PUSH_LATEST}" >> "$GITHUB_OUTPUT"
echo "platforms=${PLATFORMS}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU (multi-arch)
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Generates tags/labels. We’ll produce:
# - :<version>
# - :latest (optional)
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.vars.outputs.image_name }}
tags: |
type=raw,value=${{ steps.vars.outputs.version }}
type=raw,value=latest,enable=${{ steps.vars.outputs.push_latest == 'true' }}
labels: |
org.opencontainers.image.title=Counter-Strike: Source Game Server
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ steps.vars.outputs.platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Optional: provide a short summary in the GitHub Actions UI
- name: Summary
run: |
echo "Pushed image: ${{ steps.vars.outputs.image_name }}" >> $GITHUB_STEP_SUMMARY
echo "Tags: ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ steps.vars.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "Platforms: ${{ steps.vars.outputs.platforms }}" >> $GITHUB_STEP_SUMMARY