-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: refactor and GHA to build for CRT
- Loading branch information
Showing
13 changed files
with
293 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
name: build | ||
|
||
on: [workflow_dispatch, push] | ||
|
||
env: | ||
PKG_NAME: "http-echo" | ||
|
||
jobs: | ||
get-go-version: | ||
name: "Determine Go toolchain version" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
go-version: ${{ steps.get-go-version.outputs.go-version }} | ||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 | ||
with: | ||
# This is the minimum required version. Go 1.21+ should pull in new | ||
# toolchains as indicated in go.mod. | ||
go-version: '1.21' | ||
- name: Determine Go version | ||
id: get-go-version | ||
# With go1.21+, we can use `go version` to print out the exact toolchain that will be used | ||
run: | | ||
echo "Building with Go $(go version | awk '{print $3}' | sed -e 's/^go//')" | ||
echo "go-version=$(go version | awk '{print $3}' | sed -e 's/^go//')" >> $GITHUB_OUTPUT | ||
set-product-version: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
product-version: ${{ steps.set-product-version.outputs.product-version }} | ||
product-base-version: ${{ steps.set-product-version.outputs.base-product-version }} | ||
product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} | ||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- name: Set Product version | ||
id: set-product-version | ||
uses: hashicorp/actions-set-product-version@v1 | ||
|
||
generate-metadata-file: | ||
needs: set-product-version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
filepath: ${{ steps.generate-metadata-file.outputs.filepath }} | ||
steps: | ||
- name: "Checkout directory" | ||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- name: Generate metadata file | ||
id: generate-metadata-file | ||
uses: hashicorp/actions-generate-metadata@v1 | ||
with: | ||
version: ${{ needs.set-product-version.outputs.product-version }} | ||
product: ${{ env.PKG_NAME }} | ||
repositoryOwner: "hashicorp" | ||
repository: "http-echo" | ||
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | ||
with: | ||
name: metadata.json | ||
path: ${{ steps.generate-metadata-file.outputs.filepath }} | ||
|
||
build-other: | ||
needs: | ||
- get-go-version | ||
- set-product-version | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
goos: [windows] | ||
goarch: ["386", "amd64"] | ||
|
||
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build | ||
|
||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
|
||
- uses: hashicorp/[email protected] | ||
env: | ||
BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} | ||
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} | ||
METADATA_VERSION: ${{ env.METADATA }} | ||
with: | ||
product_name: ${{ env.PKG_NAME }} | ||
product_version: ${{ needs.set-product-version.outputs.product-version }} | ||
go_version: ${{ needs.get-go-version.outputs.go-version }} | ||
os: ${{ matrix.goos }} | ||
arch: ${{ matrix.goarch }} | ||
reproducible: report | ||
instructions: | | ||
make build | ||
build-linux: | ||
needs: | ||
- get-go-version | ||
- set-product-version | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
goos: [linux] | ||
goarch: ["arm", "arm64", "386", "amd64"] | ||
|
||
fail-fast: true | ||
|
||
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build | ||
|
||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
|
||
- uses: hashicorp/[email protected] | ||
env: | ||
BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} | ||
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} | ||
METADATA_VERSION: ${{ env.METADATA }} | ||
with: | ||
product_name: ${{ env.PKG_NAME }} | ||
product_version: ${{ needs.set-product-version.outputs.product-version }} | ||
go_version: ${{ needs.get-go-version.outputs.go-version }} | ||
os: ${{ matrix.goos }} | ||
arch: ${{ matrix.goarch }} | ||
reproducible: report | ||
instructions: | | ||
make build | ||
build-darwin: | ||
needs: | ||
- get-go-version | ||
- set-product-version | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
goos: [darwin] | ||
goarch: ["amd64", "arm64"] | ||
fail-fast: true | ||
|
||
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build | ||
|
||
env: | ||
GOOS: ${{ matrix.goos }} | ||
GOARCH: ${{ matrix.goarch }} | ||
|
||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
|
||
- uses: hashicorp/[email protected] | ||
env: | ||
BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} | ||
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} | ||
METADATA_VERSION: ${{ env.METADATA }} | ||
with: | ||
product_name: ${{ env.PKG_NAME }} | ||
product_version: ${{ needs.set-product-version.outputs.product-version }} | ||
go_version: ${{ needs.get-go-version.outputs.go-version }} | ||
os: ${{ matrix.goos }} | ||
arch: ${{ matrix.goarch }} | ||
reproducible: report | ||
instructions: | | ||
make build | ||
build-docker-default: | ||
name: Docker ${{ matrix.arch }} default release build | ||
needs: | ||
- set-product-version | ||
- build-linux | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
arch: ["arm64", "amd64"] | ||
env: | ||
repo: ${{ github.event.repository.name }} | ||
version: ${{ needs.set-product-version.outputs.product-version }} | ||
|
||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- name: Docker Build (Action) | ||
uses: hashicorp/actions-docker-build@v1 | ||
with: | ||
smoke_test: | | ||
TEST_VERSION="$(docker run "${IMAGE_NAME}" -version | awk '/http-echo/{print $2}' | sed s/v//)" | ||
if [ "${TEST_VERSION}" != "${version}" ]; then | ||
echo "Test FAILED" | ||
echo "Test Version: ${TEST_VERSION}" | ||
echo "Version: ${version}" | ||
exit 1 | ||
fi | ||
echo "Test PASSED" | ||
version: ${{ env.version }} | ||
target: default | ||
arch: ${{ matrix.arch }} | ||
tags: | | ||
docker.io/hashicorp/${{env.repo}}:${{env.version}} | ||
dev_tags: | | ||
docker.io/hashicorppreview/${{ env.repo }}:${{ env.version }}-dev | ||
docker.io/hashicorppreview/${{ env.repo }}:${{ env.version }}-${{ github.sha }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
### Custom ### | ||
/bin | ||
/pkg | ||
dist/ | ||
|
||
### Golang ### | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
FROM gcr.io/distroless/static-debian12:nonroot as default | ||
|
||
# TARGETOS and TARGETARCH are set automatically when --platform is provided. | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ARG PRODUCT_VERSION | ||
ARG BIN_NAME | ||
|
||
LABEL name="http-echo" \ | ||
maintainer="HashiCorp Consul Team <[email protected]>" \ | ||
vendor="HashiCorp" \ | ||
version=$PRODUCT_VERSION \ | ||
release=$PRODUCT_VERSION \ | ||
summary="A test webserver that echos a response. You know, for kids." | ||
|
||
COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME / | ||
|
||
EXPOSE 5678/tcp | ||
|
||
ENV ECHO_TEXT="hello-world" | ||
|
||
ENTRYPOINT ["/http-echo"] |
Oops, something went wrong.