diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3c78f13..172c407 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,6 +4,8 @@ on: push: tags: - 'v*' + branches: + - 'main' jobs: release: @@ -23,6 +25,7 @@ jobs: CGO_ENABLED=0 GOOS=linux go build -o caterpillar ./cmd/caterpillar/caterpillar.go - name: Create Release + if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 with: files: caterpillar @@ -31,3 +34,31 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata for Docker + id: tagger + uses: docker/metadata-action@v5 + with: + images: patternoss/caterpillar + tags: | + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} + type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./build/Dockerfile + push: true + tags: ${{ steps.tagger.outputs.tags }} + platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..10570a4 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.24.7-alpine AS builder + +WORKDIR /go/src/github.com/patterninc/caterpillar + +COPY . . + +# build executable +RUN go build -o caterpillar ./cmd/caterpillar/caterpillar.go +RUN chmod 755 caterpillar + +FROM alpine:3.20 +RUN mkdir -p /output +COPY --from=builder /go/src/github.com/patterninc/caterpillar/caterpillar .