From 4a9afa87843483f2447b000ebda8c065c23e521c Mon Sep 17 00:00:00 2001 From: buyfakett Date: Tue, 6 May 2025 23:22:25 +0800 Subject: [PATCH] feat: add action docker images --- .github/workflows/release-tag-version.yml | 49 +++++++++++++++++++++++ Dockerfile | 32 +++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/release-tag-version.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml new file mode 100644 index 0000000..2c649bc --- /dev/null +++ b/.github/workflows/release-tag-version.yml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..00fb819 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file