add copyright header #470
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
name: build | |
on: [workflow_dispatch, push] | |
env: | |
PRD_NAME: "consul-lambda" | |
REG_NAME: "consul-lambda-registrator" | |
EXT_NAME: "consul-lambda-extension" | |
jobs: | |
action-lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Lint workflow | |
uses: docker://docker.mirror.hashicorp.services/rhysd/actionlint:latest | |
get-go-version: | |
needs: action-lint | |
uses: ./.github/workflows/reusable-get-go-version.yml | |
get-product-version: | |
defaults: | |
run: | |
working-directory: ./consul-lambda | |
runs-on: ubuntu-latest | |
needs: action-lint | |
outputs: | |
product-version: ${{ steps.get-product-version.outputs.product-version }} | |
ldflags: ${{ steps.get-product-version.outputs.ldflags }} | |
git-short-sha: ${{ steps.get-product-version.outputs.git-short-sha }} | |
steps: | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: get product version | |
id: get-product-version | |
run: | | |
{ | |
echo "product-version=$(make version)" | |
echo "ldflags=-s -w" | |
echo "git-short-sha=$(git rev-parse --short HEAD)" | |
} >> "$GITHUB_OUTPUT" | |
generate-metadata-file: | |
defaults: | |
run: | |
working-directory: ./consul-lambda | |
runs-on: ubuntu-latest | |
needs: [action-lint, get-product-version] | |
outputs: | |
filepath: ${{ steps.generate-metadata-file.outputs.filepath }} | |
steps: | |
- name: "Checkout directory" | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Generate metadata file | |
id: generate-metadata-file | |
uses: hashicorp/actions-generate-metadata@v1 | |
with: | |
version: ${{ needs.get-product-version.outputs.product-version }} | |
product: ${{ env.PRD_NAME }} | |
repositoryOwner: "hashicorp" | |
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
with: | |
name: metadata.json | |
path: ${{ steps.generate-metadata-file.outputs.filepath }} | |
build-linux: | |
strategy: | |
matrix: | |
goos: | |
- linux | |
goarch: | |
- amd64 | |
- arm64 | |
defaults: | |
run: | |
working-directory: ./consul-lambda | |
env: | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
LDFLAGS: ${{ needs.get-product-version.outputs.ldflags }} | |
CGO_ENABLED: 0 | |
needs: | |
- get-go-version | |
- get-product-version | |
runs-on: ubuntu-latest | |
name: Go build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Setup go | |
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 | |
with: | |
go-version: ${{ needs.get-go-version.outputs.go-version }} | |
cache-dependency-path: ./consul-lambda/go.sum | |
- name: Build | |
run: | | |
mkdir dist out extensions | |
cp consul-lambda-registrator/LICENSE dist/LICENSE.txt | |
cp consul-lambda-registrator/LICENSE extensions/LICENSE.txt | |
cd consul-lambda-registrator | |
go build -ldflags="$LDFLAGS" -o ../dist/ . | |
cd .. | |
cd consul-lambda-extension | |
go build -ldflags="$LDFLAGS" -o ../extensions/ . | |
cd .. | |
zip -r -j out/${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip dist/ | |
zip -r out/${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip extensions/ | |
- name: Upload consul-lambda-registrator | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
with: | |
name: ${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip | |
path: ./consul-lambda/out/${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip | |
- name: Upload consul-lambda-extension | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
with: | |
name: ${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip | |
path: ./consul-lambda/out/${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip | |
build-docker-default: | |
strategy: | |
matrix: | |
goarch: | |
- amd64 | |
- arm64 | |
defaults: | |
run: | |
working-directory: ./consul-lambda/consul-lambda-registrator | |
name: Docker consul-lambda-registrator build | |
needs: | |
- get-product-version | |
- build-linux | |
runs-on: ubuntu-latest | |
env: | |
version: ${{ needs.get-product-version.outputs.product-version }} | |
arch: ${{ matrix.goarch }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Docker Build | |
uses: hashicorp/actions-docker-build@v1 | |
with: | |
pkg_name: ${{ env.REG_NAME }}_${{ env.version }} | |
bin_name: ${{ env.REG_NAME }} | |
version: ${{ env.version }} | |
target: release-default | |
workdir: ./consul-lambda/consul-lambda-registrator | |
arch: ${{ env.arch }} | |
tags: | | |
docker.io/hashicorp/${{ env.REG_NAME }}:${{ env.version }} | |
public.ecr.aws/hashicorp/${{ env.REG_NAME }}:${{ env.version }} | |
dev_tags: | | |
hashicorppreview/${{ env.REG_NAME }}:${{ env.version }} | |
docker.io/hashicorppreview/${{ env.REG_NAME }}:${{ env.version }} | |
upload-dev-docker: | |
name: Upload dev image (hashicorpdev/consul-lambda-registrator:<commit>) | |
environment: dockerhub/hashicorpdev | |
needs: | |
- get-product-version | |
- build-docker-default | |
runs-on: ubuntu-latest | |
env: | |
repo: ${{ github.event.repository.name }} | |
version: ${{ needs.get-product-version.outputs.product-version }} | |
arch: amd64 | |
target: release-default | |
git-short-sha: ${{ needs.get-product-version.outputs.git-short-sha }} | |
steps: | |
- name: Download image artifact | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
name: ${{ env.repo }}_${{ env.target }}_linux_${{ env.arch }}_${{ env.version }}_${{ github.sha }}.docker.dev.tar | |
- name: Docker push | |
shell: bash | |
run: | | |
TAG=hashicorpdev/${{ env.REG_NAME }}:${{ env.git-short-sha }} | |
echo "==> Load docker image from tar archive" | |
docker load -i "${{ env.repo }}_${{ env.target }}_linux_${{ env.arch }}_${{ env.version }}_${{ github.sha }}.docker.dev.tar" | |
echo "==> Tag docker image $TAG" | |
docker tag "hashicorppreview/${{ env.REG_NAME }}:${{ env.version }}" "$TAG" | |
echo "==> Docker login" | |
echo ${{ secrets.DOCKER_PASS }} | docker login -u=${{ secrets.DOCKER_USER }} --password-stdin | |
echo "==> Push docker image $TAG" | |
docker push "$TAG" | |
- name: Docker push (latest) | |
shell: bash | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
TAG=hashicorpdev/${{ env.REG_NAME }}:latest | |
echo "==> Tag docker image $TAG as :latest" | |
docker tag "hashicorpdev/${{ env.REG_NAME }}:${{ env.git-short-sha }}" "$TAG" | |
echo "==> Push docker image $TAG" | |
docker push "$TAG" |