From f8755562f368bb5099497103078295f409b0f4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Thu, 21 May 2026 14:22:54 +0200 Subject: [PATCH] ci: add Dockerfile and GitHub Actions workflow to publish to ghcr.io MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mickaël Canévet --- .dockerignore | 6 ++++ .github/workflows/ci.yaml | 68 +++++++++++++++++++++++++++++++++++++ .github/workflows/lint.yaml | 15 -------- .github/workflows/test.yaml | 16 --------- Dockerfile | 12 +++++++ 5 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/lint.yaml delete mode 100644 .github/workflows/test.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6e53d90 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.github +*.md +LICENSE +*_test.go +talos-meta-tool diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..465be0c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: ci + +on: + push: + branches: ["**"] + tags: ["v*"] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: go test ./... + + lint: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - uses: golangci/golangci-lint-action@v7 + with: + version: v2.12.2 + + docker: + needs: [test, lint] + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=tag + + - uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 370cf6e..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: lint - -on: - push: - branches: ["**"] - pull_request: - -jobs: - golangci-lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: golangci/golangci-lint-action@v7 - with: - version: v2.12.2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 7354abf..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: test - -on: - push: - branches: ["**"] - pull_request: - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - run: go test ./... diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c666a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.26.3-alpine AS builder +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +ARG TARGETARCH +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ + go build -trimpath -ldflags="-s -w" -o /talos-meta-tool . + +FROM scratch +COPY --from=builder /talos-meta-tool /talos-meta-tool +ENTRYPOINT ["/talos-meta-tool"]