From 7ce059a278e728b6a2d72047d1e81557dc1204c5 Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Fri, 10 Nov 2023 13:44:12 -0500 Subject: [PATCH] wip --- .github/workflows/pull-docker-image.yml | 51 -------- .../push-docker-image-to-registries.yml | 83 ------------- .github/workflows/release.yml | 62 ++++++++++ .goreleaser.yaml | 116 ++++++++++++++++++ tools/goreleaser.containerfile | 17 +++ 5 files changed, 195 insertions(+), 134 deletions(-) delete mode 100644 .github/workflows/pull-docker-image.yml delete mode 100644 .github/workflows/push-docker-image-to-registries.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml create mode 100644 tools/goreleaser.containerfile diff --git a/.github/workflows/pull-docker-image.yml b/.github/workflows/pull-docker-image.yml deleted file mode 100644 index eb0170b7ef..0000000000 --- a/.github/workflows/pull-docker-image.yml +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2023 Democratized Data Foundation -# -# Use of this software is governed by the Business Source License -# included in the file licenses/BSL.txt. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0, included in the file -# licenses/APL.txt. - -# This workflow validates that the images pushed to the container -# registries can be pulled then run sucessfully. -name: Pull Docker Image Workflow - -on: - workflow_run: - # Warning: this workflow must NOT: - # - interact with any new code. - # - checkout new code. - # - build/compile anything (only pull). - # - make any indirect calls (i.e. make xyz, or npm install, etc.) - # Note this workflow: - # - will use the base's (or default) workflow file's state. - # - doesn't run on the PR or the branch coming in, it runs on the default branch. - # - has read-write repo token - # - has access to secrets - workflows: ["Push Docker Image To Registries Workflow"] - types: - - completed - -jobs: - pull-docker-image: - name: Pull docker image job - - if: ${{ github.event.workflow_run.conclusion == 'success' }} - - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - image_tag: - - sourcenetwork/defradb:latest - - ghcr.io/sourcenetwork/defradb:latest - - steps: - - name: Pull Docker image - run: docker pull ${{ matrix.image_tag }} - - - name: Test Docker image - run: docker run --rm ${{ matrix.image_tag }} diff --git a/.github/workflows/push-docker-image-to-registries.yml b/.github/workflows/push-docker-image-to-registries.yml deleted file mode 100644 index 47c4e98046..0000000000 --- a/.github/workflows/push-docker-image-to-registries.yml +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2023 Democratized Data Foundation -# -# Use of this software is governed by the Business Source License -# included in the file licenses/BSL.txt. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0, included in the file -# licenses/APL.txt. - -# This workflow builds a Docker container image, if the build is successful -# then it will deploy the image to DockerHub & GitHub container registries. -name: Push Docker Image To Registries Workflow - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - -env: - TEST_TAG: sourcenetwork/defradb:test - -jobs: - push-docker-image-to-registries: - name: Push Docker image to registries job - - runs-on: ubuntu-latest - - permissions: - packages: write - contents: read - - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build Docker image - uses: docker/build-push-action@v4 - with: - context: . - file: tools/defradb.containerfile - load: true - tags: ${{ env.TEST_TAG }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Test Docker image - run: docker run --rm ${{ env.TEST_TAG }} - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: | - sourcenetwork/defradb - ghcr.io/${{ github.repository }} - - - name: Push Docker images - uses: docker/build-push-action@v4 - with: - context: . - file: tools/defradb.containerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..e3cdc1506e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +# Copyright 2023 Democratized Data Foundation +# +# Use of this software is governed by the Business Source License +# included in the file licenses/BSL.txt. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0, included in the file +# licenses/APL.txt. + +# This workflow builds the AMI using packer, if the build is successfull +# then it will deploy the AMI using terraform apply, onto AWS. +name: Release workflow + +on: + push: + tags: ['v*'] + +permissions: + contents: write + packages: write + issues: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout code into the directory + uses: actions/checkout@v3 + + - name: Setup Go environment explicitly + uses: actions/setup-go@v3 + with: + go-version: "1.20" + check-latest: true + + - name: Build modules + run: make deps:modules + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # - name: Log in to the 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@v5 + with: + distribution: goreleaser-pro + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000000..e3424e808d --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,116 @@ +version: 1 + +dist: ./build + +before: + hooks: + - go mod tidy + - make deps:playground + +after: + hooks: + - cmd: docker pull {{ .Env.GITHUB_REPOSITORY }}:latest + - cmd: docker run --rm {{ .Env.GITHUB_REPOSITORY }}:latest + +builds: + - id: "defradb" + main: ./cmd/defradb + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + + - id: "defradb+pg" + main: ./cmd/defradb + env: + - CGO_ENABLED=0 + flags: + - -tags=playground + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + + +archives: + - id: defradb+pg + builds: + - defradb+pg + format: binary + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: '{{ .Binary }}+pg_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}{{- if .Arm }}v{{ .Arm }}{{ end }}' + - id: defradb + builds: + - defradb + format: binary + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}{{- if .Arm }}v{{ .Arm }}{{ end }}' + + +release: + github: + owner: fredcarle + name: defradb + draft: true + header: | + DefraDB v0.8 is a major pre-production release. Until the stable version 1.0 is reached, the SemVer minor patch number will denote notable releases, which will give the project freedom to experiment and explore potentially breaking changes. + + To get a full outline of the changes, we invite you to review the official changelog below. This release does include a Breaking Change to existing v0.7.x databases. If you need help migrating an existing deployment, reach out at hello@source.network or join our Discord at https://discord.source.network/. + name_template: "v{{.Version}} Release" + +changelog: + sort: asc + groups: + - title: Features + regexp: '^feat:.*' + order: 0 + - title: Fix + regexp: '^fix:.*' + order: 1 + - title: Tooling + regexp: '^tools:.*' + order: 2 + - title: Documentation + regexp: '^docs:.*' + order: 3 + - title: Refactoring + regexp: '^refactor:.*' + order: 4 + - title: Testing + regexp: '^test:.*' + order: 5 + +source: + enabled: true + +# milestones: +# - close: true +# fail_on_error: true +# name_template: "DefraDB v0.8" + +dockers: +- ids: + - "defradb+pg" + image_templates: + - "{{ .Env.GITHUB_REPOSITORY }}:latest" + - "{{ .Env.GITHUB_REPOSITORY }}:{{ .Version }}" + # - "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Version }}" + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.description=DefraDB is a Peer-to-Peer Edge Database." + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/amd64" + dockerfile: ./tools/goreleaser.containerfile + diff --git a/tools/goreleaser.containerfile b/tools/goreleaser.containerfile new file mode 100644 index 0000000000..d8a8af4e6b --- /dev/null +++ b/tools/goreleaser.containerfile @@ -0,0 +1,17 @@ +# syntax=docker/dockerfile:1 + +# An image to run defradb. + +# Stage: RUN +FROM debian:bookworm-slim +COPY defradb /defradb + +# Documents which ports are normally used. +# To publish the ports: `docker run -p 9181:9181` ... +EXPOSE 9161 +EXPOSE 9171 +EXPOSE 9181 + +# Default command provided for convenience. +# e.g. docker run -p 9181:9181 source/defradb start --url 0.0.0.0:9181 +ENTRYPOINT [ "/defradb" ]