Skip to content

Commit

Permalink
Merge pull request #6 from hasura/dockerize-deploy-package
Browse files Browse the repository at this point in the history
Automate release process
  • Loading branch information
gneeri authored Jun 3, 2024
2 parents 1a6f77b + 81b57d2 commit 68f4209
Show file tree
Hide file tree
Showing 12 changed files with 3,504 additions and 38 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/deploy-stage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: Deploy connector, release cli on github
on:
push:
branches:
- main
tags:
- 'v*'

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-cli-binaries:
name: build the CLI binaries
strategy:
matrix:
include:
- runner: ubuntu-latest
target: x86_64-unknown-linux-musl
goos: linux
goarch: amd64
- runner: ubuntu-latest
target: aarch64-unknown-linux-musl
goos: linux
goarch: arm64
- runner: macos-latest
target: x86_64-apple-darwin
goos: darwin
goarch: amd64
- runner: macos-latest
target: aarch64-apple-darwin
goos: darwin
goarch: arm64
- runner: windows-latest
target: x86_64-pc-windows-msvc
goos: windows
goarch: amd64
extension: .exe
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Build binary
run: |
mkdir -p release
echo "Building binary file for target: ${{ matrix.goos }}${{ matrix.goarch }}"
env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ./release/ndc-elasticsearch-cli-${{ matrix.target }}${{ matrix.extension }}
- uses: actions/upload-artifact@v4
with:
name: ndc-elasticsearch-cli-${{ matrix.target }}${{ matrix.extension }}
path: release/
if-no-files-found: error

release:
name: release to GitHub
permissions:
contents: write
needs:
- build-and-push-image
- build-cli-binaries
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
path: release/artifacts
merge-multiple: true

- name: generate CLI manifest
run: |
set -evo pipefail
ROOT="$(pwd)"
export CLI_VERSION="$GITHUB_REF_NAME"
export LINUX_AMD64_SHA256=$(sha256sum ${ROOT}/release/artifacts/ndc-elasticsearch-cli-x86_64-unknown-linux-musl | cut -f1 -d' ')
export MACOS_AMD64_SHA256=$(sha256sum ${ROOT}/release/artifacts/ndc-elasticsearch-cli-x86_64-apple-darwin | cut -f1 -d' ')
export WINDOWS_AMD64_SHA256=$(sha256sum ${ROOT}/release/artifacts/ndc-elasticsearch-cli-x86_64-pc-windows-msvc.exe | cut -f1 -d' ')
export LINUX_ARM64_SHA256=$(sha256sum ${ROOT}/release/artifacts/ndc-elasticsearch-cli-aarch64-unknown-linux-musl | cut -f1 -d' ')
export MACOS_ARM64_SHA256=$(sha256sum ${ROOT}/release/artifacts/ndc-elasticsearch-cli-aarch64-apple-darwin | cut -f1 -d' ')
mkdir -p "${ROOT}/release/"
cat "${ROOT}/ci/templates/manifest.yaml" | envsubst > "${ROOT}/release/manifest.yaml"
- uses: actions/upload-artifact@v4
with:
name: manifest.yaml
path: release/manifest.yaml
if-no-files-found: error

- name: Build connector definition
run: |
set -evo pipefail
ROOT="$(pwd)"
export DOCKER_IMAGE="ghcr.io/hasura/ndc-elasticsearch:$GITHUB_REF_NAME"
export CLI_VERSION=$GITHUB_REF_NAME
mkdir -p "${ROOT}/release/connector-definition/.hasura-connector/"
cat "${ROOT}/ci/templates/connector-metadata.yaml" | envsubst > "${ROOT}/release/connector-definition/.hasura-connector/connector-metadata.yaml"
tar -czvf "${ROOT}/release/artifacts/connector-definition.tgz" --directory "${ROOT}/release/connector-definition/" .
- uses: actions/upload-artifact@v4
with:
name: connector-definition.tgz
path: ./release/artifacts/connector-definition.tgz
compression-level: 0 # Already compressed

- name: Get version from tag
id: get-version
run: |
echo "tagged_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
shell: bash

- uses: mindsers/changelog-reader-action@v2
id: changelog-reader
with:
version: ${{ steps.get-version.outputs.tagged_version }}
path: ./CHANGELOG.md

- name: create a draft release
uses: ncipollo/release-action@v1
with:
draft: true
tag: v${{ steps.get-version.outputs.tagged_version }}
body: ${{ steps.changelog-reader.outputs.changes }}
artifacts: release/artifacts/*
3 changes: 0 additions & 3 deletions .hasura-connector/.dockerignore

This file was deleted.

17 changes: 0 additions & 17 deletions .hasura-connector/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions .hasura-connector/connector-metadata.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0]

- Initial release of the Hasura connector for Elasticsearch.
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Stage 1: Build the Go binary
FROM golang:1.22 AS builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ndc-elasticsearch

# Stage 2: Create a minimal image with the Go binary
FROM alpine:3.18.3

# Install necessary certificates for the application to run
RUN apk --no-cache add ca-certificates

# Set the working directory inside the container
WORKDIR /root/

RUN mkdir -p /etc/connector

# Copy the Go binary from the builder stage
COPY --from=builder /app/ndc-elasticsearch .

# Expose the port on which the service will run
EXPOSE 8080

ENV HASURA_CONFIGURATION_DIRECTORY=/etc/connector

# Run the web service on container startup.
ENTRYPOINT [ "./ndc-elasticsearch" ]
CMD [ "serve" ]
25 changes: 25 additions & 0 deletions ci/templates/connector-metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
packagingDefinition:
type: PrebuiltDockerImage
dockerImage: "${DOCKER_IMAGE}"
supportedEnvironmentVariables:
- name: ELASTICSEARCH_URL
description: The comma-separated list of Elasticsearch host addresses for connection.
- name: ELASTICSEARCH_USERNAME
description: The username for authenticating to the Elasticsearch cluster.
- name: ELASTICSEARCH_PASSWORD
description: The password for the Elasticsearch user account.
- name: ELASTICSEARCH_API_KEY
description: The Elasticsearch API key for authenticating to the Elasticsearch cluster.
- name: ELASTICSEARCH_CA_CERT_PATH
description: The path to the Certificate Authority (CA) certificate for verifying the Elasticsearch server's SSL certificate.
- name: ELASTICSEARCH_INDEX_PATTERN
description: The pattern for matching Elasticsearch indices, potentially including wildcards, used by the connector.
commands:
update: hasura-elasticsearch update
cliPlugin:
name: elasticsearch
version: "${CLI_VERSION}"
dockerComposeWatch:
- path: ./
target: /etc/connector
action: sync+restart
41 changes: 41 additions & 0 deletions ci/templates/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: elasticsearch
version: "${CLI_VERSION}"
shortDescription: "CLI plugin for Hasura ndc-elasticsearch"
homepage: https://hasura.io/connectors/elasticsearch
hidden: true
platforms:
- selector: darwin-arm64
uri: "https://github.com/hasura/ndc-elasticsearch/releases/download/${CLI_VERSION}/ndc-elasticsearch-cli-aarch64-apple-darwin"
sha256: "${MACOS_ARM64_SHA256}"
bin: "hasura-elasticsearch"
files:
- from: "./ndc-elasticsearch-cli-aarch64-apple-darwin"
to: "hasura-elasticsearch"
- selector: linux-arm64
uri: "https://github.com/hasura/ndc-elasticsearch/releases/download/${CLI_VERSION}/ndc-elasticsearch-cli-aarch64-unknown-linux-musl"
sha256: "${LINUX_ARM64_SHA256}"
bin: "hasura-elasticsearch"
files:
- from: "./ndc-elasticsearch-cli-aarch64-unknown-linux-musl"
to: "hasura-elasticsearch"
- selector: darwin-amd64
uri: "https://github.com/hasura/ndc-elasticsearch/releases/download/${CLI_VERSION}/ndc-elasticsearch-cli-x86_64-apple-darwin"
sha256: "${MACOS_AMD64_SHA256}"
bin: "hasura-elasticsearch"
files:
- from: "./ndc-elasticsearch-cli-x86_64-apple-darwin"
to: "hasura-elasticsearch"
- selector: windows-amd64
uri: "https://github.com/hasura/ndc-elasticsearch/releases/download/${CLI_VERSION}/ndc-elasticsearch-cli-x86_64-pc-windows-msvc.exe"
sha256: "${WINDOWS_AMD64_SHA256}"
bin: "hasura-elasticsearch.exe"
files:
- from: "./ndc-elasticsearch-cli-x86_64-pc-windows-msvc.exe"
to: "hasura-elasticsearch.exe"
- selector: linux-amd64
uri: "https://github.com/hasura/ndc-elasticsearch/releases/download/${CLI_VERSION}/ndc-elasticsearch-cli-x86_64-unknown-linux-musl"
sha256: "${LINUX_AMD64_SHA256}"
bin: "hasura-elasticsearch"
files:
- from: "./ndc-elasticsearch-cli-x86_64-unknown-linux-musl"
to: "hasura-elasticsearch"
Loading

0 comments on commit 68f4209

Please sign in to comment.