2023-03-31 19:02:40 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
# This workflow builds a dev binary and distributes a Docker image on every push to the main branch.
|
|
|
|
name: build-artifacts
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
env:
|
2023-06-21 15:26:27 +00:00
|
|
|
GOPRIVATE: github.com/hashicorp # Required for enterprise deps
|
2023-03-31 19:02:40 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
setup:
|
|
|
|
name: Setup
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
compute-small: ${{ steps.setup-outputs.outputs.compute-small }}
|
|
|
|
compute-medium: ${{ steps.setup-outputs.outputs.compute-medium }}
|
|
|
|
compute-large: ${{ steps.setup-outputs.outputs.compute-large }}
|
|
|
|
compute-xl: ${{ steps.setup-outputs.outputs.compute-xl }}
|
|
|
|
steps:
|
2024-05-14 19:49:03 +00:00
|
|
|
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
2023-03-31 19:02:40 +00:00
|
|
|
- id: setup-outputs
|
|
|
|
name: Setup outputs
|
|
|
|
run: ./.github/scripts/get_runner_classes.sh
|
|
|
|
|
2024-01-08 22:18:41 +00:00
|
|
|
get-go-version:
|
|
|
|
uses: ./.github/workflows/reusable-get-go-version.yml
|
|
|
|
|
2023-03-31 19:02:40 +00:00
|
|
|
dev-build-push:
|
2024-01-08 22:18:41 +00:00
|
|
|
needs:
|
|
|
|
- setup
|
|
|
|
- get-go-version
|
2023-04-07 17:10:47 +00:00
|
|
|
runs-on: ${{ fromJSON(needs.setup.outputs.compute-large) }}
|
2023-03-31 19:02:40 +00:00
|
|
|
permissions:
|
|
|
|
id-token: write # NOTE: this permission is explicitly required for Vault auth.
|
|
|
|
contents: read
|
|
|
|
steps:
|
|
|
|
# NOTE: ENT specific step as we store secrets in Vault.
|
|
|
|
- name: Authenticate to Vault
|
|
|
|
if: ${{ endsWith(github.repository, '-enterprise') }}
|
|
|
|
id: vault-auth
|
|
|
|
run: vault-auth
|
|
|
|
|
|
|
|
# NOTE: ENT specific step as we store secrets in Vault.
|
|
|
|
- name: Fetch Secrets
|
|
|
|
if: ${{ endsWith(github.repository, '-enterprise') }}
|
|
|
|
id: secrets
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: hashicorp/vault-action@v3
|
2023-03-31 19:02:40 +00:00
|
|
|
with:
|
|
|
|
url: ${{ steps.vault-auth.outputs.addr }}
|
|
|
|
caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }}
|
|
|
|
token: ${{ steps.vault-auth.outputs.token }}
|
|
|
|
secrets: |
|
|
|
|
kv/data/github/${{ github.repository }}/dockerhub username | DOCKERHUB_USERNAME;
|
|
|
|
kv/data/github/${{ github.repository }}/dockerhub token | DOCKERHUB_TOKEN;
|
|
|
|
|
2024-05-14 19:49:03 +00:00
|
|
|
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
2023-03-31 19:02:40 +00:00
|
|
|
|
|
|
|
# NOTE: ENT specific step as we need to set elevated GitHub permissions.
|
|
|
|
- name: Setup Git
|
|
|
|
if: ${{ endsWith(github.repository, '-enterprise') }}
|
|
|
|
run: git config --global url."https://${{ secrets.ELEVATED_GITHUB_TOKEN }}:@github.com".insteadOf "https://github.com"
|
|
|
|
|
2024-05-14 19:49:03 +00:00
|
|
|
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
|
2023-03-31 19:02:40 +00:00
|
|
|
with:
|
2024-01-08 22:18:41 +00:00
|
|
|
go-version: ${{ needs.get-go-version.outputs.go-version }}
|
2023-04-10 22:42:42 +00:00
|
|
|
|
|
|
|
- run: go env
|
2023-03-31 19:02:40 +00:00
|
|
|
|
|
|
|
- name: Build dev binary
|
|
|
|
run: make dev
|
|
|
|
|
|
|
|
- name: Set env vars
|
|
|
|
run: |
|
|
|
|
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
|
|
|
echo "GITHUB_BUILD_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
|
2023-03-31 19:02:40 +00:00
|
|
|
|
2023-08-22 14:46:03 +00:00
|
|
|
# NOTE: conditional specific logic as we store secrets in Vault in ENT and use GHA secrets in CE.
|
2023-03-31 19:02:40 +00:00
|
|
|
- name: Login to Docker Hub
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
|
2023-03-31 19:02:40 +00:00
|
|
|
with:
|
|
|
|
username: ${{ endsWith(github.repository, '-enterprise') && steps.secrets.outputs.DOCKERHUB_USERNAME || secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ endsWith(github.repository, '-enterprise') && steps.secrets.outputs.DOCKERHUB_TOKEN || secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Docker build and push
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
|
2023-03-31 19:02:40 +00:00
|
|
|
with:
|
|
|
|
context: ./bin
|
|
|
|
file: ./build-support/docker/Consul-Dev.dockerfile
|
|
|
|
labels: COMMIT_SHA=${{ github.sha }},GITHUB_BUILD_URL=${{ env.GITHUB_BUILD_URL }}
|
|
|
|
push: true
|
2023-04-10 22:42:42 +00:00
|
|
|
# This is required or else the image is not pullable.
|
|
|
|
# See https://github.com/docker/build-push-action/issues/820 for further
|
|
|
|
# details.
|
|
|
|
# TODO - investigate further and see if we can find a solution where we
|
|
|
|
# we don't have to know to set this.
|
|
|
|
provenance: false
|
2023-03-31 19:02:40 +00:00
|
|
|
tags: |
|
|
|
|
hashicorpdev/${{ github.event.repository.name }}:${{ env.SHORT_SHA }}
|
|
|
|
hashicorpdev/${{ github.event.repository.name }}:latest
|
2023-04-06 22:29:32 +00:00
|
|
|
|
|
|
|
# This is job is required for branch protection as a required gihub check
|
|
|
|
# because GitHub actions show up as checks at the job level and not the
|
|
|
|
# workflow level. This is currently a feature request:
|
|
|
|
# https://github.com/orgs/community/discussions/12395
|
|
|
|
#
|
|
|
|
# This job must:
|
|
|
|
# - be placed after the fanout of a workflow so that everything fans back in
|
|
|
|
# to this job.
|
|
|
|
# - "need" any job that is part of the fan out / fan in
|
|
|
|
# - implement the if logic because we have conditional jobs
|
|
|
|
# (go-test-enteprise) that this job needs and this would potentially get
|
|
|
|
# skipped if a previous job got skipped. So we use the if clause to make
|
|
|
|
# sure it does not get skipped.
|
|
|
|
|
|
|
|
build-artifacts-success:
|
|
|
|
needs:
|
|
|
|
- setup
|
|
|
|
- dev-build-push
|
|
|
|
runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }}
|
2023-04-25 20:17:48 +00:00
|
|
|
if: ${{ always() }}
|
2023-04-06 22:29:32 +00:00
|
|
|
steps:
|
2023-04-25 20:17:48 +00:00
|
|
|
- name: evaluate upstream job results
|
|
|
|
run: |
|
|
|
|
# exit 1 if failure or cancelled result for any upstream job
|
|
|
|
if printf '${{ toJSON(needs) }}' | grep -E -i '\"result\": \"(failure|cancelled)\"'; then
|
|
|
|
printf "Tests failed or workflow cancelled:\n\n${{ toJSON(needs) }}"
|
|
|
|
exit 1
|
|
|
|
fi
|