feat: add action docker images

This commit is contained in:
2025-05-06 23:22:25 +08:00
parent 34723f4b51
commit 4a9afa8784
2 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,49 @@
name: release-tag-version
on:
push:
tags:
- "v*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write # to publish to ghcr.io
steps:
- uses: actions/checkout@v4
- run: git fetch --unshallow --quiet --tags --force
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: |-
ghcr.io/rayzggz/server_torii
# this will generate tags in the following format:
# latest
# 1
# 1.2
# 1.2.3
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to GHCR using PAT
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build rootful docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

32
Dockerfile Normal file
View File

@ -0,0 +1,32 @@
ARG ALPINE_VERSION=3.21
ARG GO_VERSION=1.23.5
ARG AUTHOR=Rayzggz
ARG SERVER_NAME=server_torii
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
ARG ALPINE_VERSION
ARG GO_VERSION
ARG SERVER_NAME
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
COPY . .
RUN set -eux; \
TARGETOS=${TARGETOS:-linux}; \
TARGETARCH=${TARGETARCH:-amd64}; \
echo "Building for TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH}"; \
go mod tidy; \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o /app/${SERVER_NAME}
FROM alpine:${ALPINE_VERSION} AS final
ARG SERVER_NAME
COPY --from=builder /app/${SERVER_NAME} /app/${SERVER_NAME}
EXPOSE 8888
ENTRYPOINT ["/app/server_torii"]