diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 90ff635..2d1aa9f 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,12 +1,18 @@ name: 🐳 Build & Push Docker Image on: - release: - types: [published] + workflow_call: + inputs: + tag: + description: "Release tag" + required: true + type: string env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository_owner }}/picoclaw + GHCR_REGISTRY: ghcr.io + GHCR_IMAGE_NAME: ${{ github.repository_owner }}/picoclaw + DOCKERHUB_REGISTRY: docker.io + DOCKERHUB_IMAGE_NAME: ${{ vars.DOCKERHUB_REPOSITORY }} jobs: build: @@ -20,6 +26,8 @@ jobs: # ── Checkout ────────────────────────────── - name: 📥 Checkout repository uses: actions/checkout@v4 + with: + ref: ${{ inputs.tag }} # ── Docker Buildx ───────────────────────── - name: 🔧 Set up Docker Buildx @@ -27,36 +35,42 @@ jobs: # ── Login to GHCR ───────────────────────── - name: 🔑 Login to GitHub Container Registry - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: - registry: ${{ env.REGISTRY }} + registry: ${{ env.GHCR_REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # ── Metadata (tags & labels) ────────────── - - name: 🏷️ Extract Docker metadata - id: meta - uses: docker/metadata-action@v5 + # ── Login to Docker Hub ──────────────────── + - name: 🔑 Login to Docker Hub + uses: docker/login-action@v3 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha,prefix= - type=raw,value=latest,enable={{is_default_branch}} - type=raw,value={{date 'YYYYMMDD-HHmmss'}},enable={{is_default_branch}} + registry: ${{ env.DOCKERHUB_REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # ── Metadata (tags & labels) ────────────── + - name: 🏷️ Prepare image tags + id: tags + shell: bash + run: | + tag="${{ inputs.tag }}" + echo "ghcr_tag=${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:${tag}" >> "$GITHUB_OUTPUT" + echo "ghcr_latest=${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" + echo "dockerhub_tag=${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:${tag}" >> "$GITHUB_OUTPUT" + echo "dockerhub_latest=${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" # ── Build & Push ────────────────────────── - name: 🚀 Build and push Docker image uses: docker/build-push-action@v6 with: context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + push: true + tags: | + ${{ steps.tags.outputs.ghcr_tag }} + ${{ steps.tags.outputs.ghcr_latest }} + ${{ steps.tags.outputs.dockerhub_tag }} + ${{ steps.tags.outputs.dockerhub_latest }} cache-from: type=gha cache-to: type=gha,mode=max - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64,linux/riscv64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59cc6ca..f9987b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,14 +38,18 @@ jobs: git tag -a "${{ inputs.tag }}" -m "Release ${{ inputs.tag }}" git push origin "${{ inputs.tag }}" - build-binaries: - name: Build Release Binaries + release: + name: GoReleaser Release needs: create-tag runs-on: ubuntu-latest + permissions: + contents: write + packages: write steps: - name: Checkout tag uses: actions/checkout@v4 with: + fetch-depth: 0 ref: ${{ inputs.tag }} - name: Setup Go from go.mod @@ -53,47 +57,42 @@ jobs: with: go-version-file: go.mod - - name: Build all binaries - run: make build-all + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Generate checksums - shell: bash - run: | - shasum -a 256 build/picoclaw-* > build/sha256sums.txt + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Upload release binaries artifact - uses: actions/upload-artifact@v4 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: - name: picoclaw-binaries - path: | - build/picoclaw-* - build/sha256sums.txt - if-no-files-found: error + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - create-release: - name: Create GitHub Release - needs: [create-tag, build-binaries] - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Download all artifacts - uses: actions/download-artifact@v4 + - name: Login to Docker Hub + uses: docker/login-action@v3 with: - path: release-artifacts + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Show downloaded files - run: ls -R release-artifacts - - - name: Create release - uses: softprops/action-gh-release@v2 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 with: - tag_name: ${{ inputs.tag }} - name: ${{ inputs.tag }} - draft: ${{ inputs.draft }} - prerelease: ${{ inputs.prerelease }} - files: | - release-artifacts/**/* - generate_release_notes: true + distribution: goreleaser + version: ~> v2 + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} + DOCKERHUB_IMAGE_NAME: ${{ vars.DOCKERHUB_REPOSITORY }} + + - name: Apply release flags + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release edit "${{ inputs.tag }}" \ + --draft=${{ inputs.draft }} \ + --prerelease=${{ inputs.prerelease }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a2c1583..9f4cedc 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,9 +5,11 @@ version: 2 before: hooks: - go mod tidy + - go generate ./cmd/picoclaw builds: - - env: + - id: picoclaw + env: - CGO_ENABLED=0 goos: - linux @@ -26,6 +28,22 @@ builds: - goos: windows goarch: arm +dockers_v2: + - id: picoclaw + dockerfile: Dockerfile.goreleaser + ids: + - picoclaw + images: + - "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw" + - "docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}" + tags: + - "{{ .Tag }}" + - "latest" + platforms: + - linux/amd64 + - linux/arm64 + - linux/riscv64 + archives: - formats: [tar.gz] # this name template makes the OS and Arch compatible with the results of `uname`. diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..0cdc8c6 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,10 @@ +FROM alpine:3.21 + +ARG TARGETPLATFORM + +RUN apk add --no-cache ca-certificates tzdata + +COPY $TARGETPLATFORM/picoclaw /usr/local/bin/picoclaw + +ENTRYPOINT ["picoclaw"] +CMD ["gateway"]