From bc8151452895cc41b4ad4c90b4a3ccd0ce52198a Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Mon, 20 May 2024 22:22:19 +0800 Subject: [PATCH] feat: support to publish new-dockerfile as image (#12) Co-authored-by: rick --- .github/workflows/pr.yml | 25 ++++++++++++++++++++++++ .github/workflows/release.yml | 36 ++++++++++++++++++++++++++++++++++- .gitignore | 1 - Dockerfile | 13 +++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fe2f409..0549da8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -26,3 +26,28 @@ jobs: run: go vet ./... - name: Run tests run: go test -v ./... + + image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3.3.0 + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: | + ghcr.io/flexstack/new-dockerfile + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0006b5..101e2a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,13 +2,16 @@ name: Release on: push: + tags: + - "*" + branches: + - main permissions: contents: write jobs: release: - if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - name: Checkout @@ -25,3 +28,34 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3.3.0 + - name: Log into registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: | + ghcr.io/flexstack/new-dockerfile + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 77c144a..c1b3172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules /dist/ -/Dockerfile .idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1d8312a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM docker.io/library/golang:1.21 AS builder + +ARG GOPROXY=direct +WORKDIR /app +COPY . . +RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -o new-dockerfile cmd/new-dockerfile/main.go + +FROM docker.io/library/alpine:3.19.1 + +WORKDIR /app +COPY --from=builder /app/new-dockerfile /usr/local/bin + +CMD [ "new-dockerfile" ]