From f1850a2d79d05a5ecca1b685d09b03a3b87fa6cc Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:03:18 -0500 Subject: [PATCH] chore: add docker build ci Add Dockerfile, goreleaser config, and GitHub workflows to build docker images and publish them to ghcr. Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- .github/workflows/main.yaml | 29 ++++++++++++++++++++++-- .github/workflows/release.yaml | 15 ++++++++++++- .goreleaser.yml | 40 ++++++++++++++++++++++++++++++++++ Dockerfile | 9 ++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index bf95f9d4..798d5d2a 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -11,9 +11,10 @@ on: permissions: contents: write + packages: write jobs: - release-snapshot: + release-main: runs-on: ubuntu-22.04 steps: - name: Checkout @@ -24,7 +25,20 @@ jobs: uses: actions/setup-go@v4 with: cache: false - go-version: "1.21" + go-version: "1.22" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + buildkitd-flags: --debug + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@v4 with: @@ -34,3 +48,14 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_PROJECT_TOKEN: ${{ secrets.GH_PROJECT_TOKEN }} + - name: Push Docker Images + run: | + VERSION=v$(cat releases/metadata.json | jq -r .version) + IMAGES=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "$VERSION") + for i in ${IMAGES}; do + docker push $i + done + docker manifest create ghcr.io/gptscript-ai/gptscript:main ${IMAGES} + docker manifest push ghcr.io/gptscript-ai/gptscript:main + docker manifest create ghcr.io/gptscript-ai/gptscript:${VERSION} ${IMAGES} + docker manifest push ghcr.io/gptscript-ai/gptscript:${VERSION} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1ad22624..9b3b51eb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,7 +20,20 @@ jobs: uses: actions/setup-go@v4 with: cache: false - go-version: "1.21" + go-version: "1.22" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + buildkitd-flags: --debug + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@v4 with: diff --git a/.goreleaser.yml b/.goreleaser.yml index 99b892f5..fc9b8483 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -65,3 +65,43 @@ brews: owner: gptscript-ai name: homebrew-tap token: "{{ .Env.GH_PROJECT_TOKEN }}" + +dockers: + - use: buildx + goos: linux + goarch: amd64 + image_templates: + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-amd64 + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source=https://github.com/gptscript-ai/gptscript" + - "--platform=linux/amd64" + - use: buildx + goos: linux + goarch: arm64 + image_templates: + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-arm64 + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source=https://github.com/gptscript-ai/gptscript" + - "--platform=linux/arm64" + +docker_manifests: + - use: docker + name_template: ghcr.io/gptscript-ai/gptscript:v{{ .Version }} + image_templates: + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-amd64 + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-arm64 + - use: docker + name_template: ghcr.io/gptscript-ai/gptscript:latest + image_templates: + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-amd64 + - ghcr.io/gptscript-ai/gptscript:v{{ .Version }}-arm64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9e40f485 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.22.0-alpine3.19 AS build +RUN apk add -U --no-cache make git +COPY / /src/gptscript +WORKDIR /src/gptscript +RUN make build + +FROM alpine AS release +COPY --from=build /src/gptscript/bin /usr/local/bin/ +ENTRYPOINT ["/usr/local/bin/gptscript"]