mirror of
https://github.com/openziti/ziti.git
synced 2026-10-11 23:12:35 +00:00
242 lines
8.8 KiB
YAML
242 lines
8.8 KiB
YAML
name: build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- release-v*
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
GOFLAGS: "-trimpath"
|
|
GOX_OUTPUT: "release/{{.Arch}}/{{.OS}}/{{.Dir}}"
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
gh_ci_key: ${{ secrets.GH_CI_KEY }}
|
|
|
|
jobs:
|
|
mac-os-build:
|
|
name: Build Mac OS binaries
|
|
runs-on: macos-10.15
|
|
steps:
|
|
- name: Git Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Go
|
|
uses: actions/setup-go@v2
|
|
with:
|
|
go-version: '~1.18.1'
|
|
|
|
- name: Install Ziti CI
|
|
uses: netfoundry/ziti-ci@v1
|
|
|
|
- name: Build and Test
|
|
run: |
|
|
go install github.com/mitchellh/gox@latest
|
|
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
|
$(go env GOPATH)/bin/gox -cgo -os=darwin -arch=amd64 -output=$GOX_OUTPUT ./...
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: darwin-release-${{ github.run_id }}
|
|
path: release/
|
|
retention-days: 5
|
|
|
|
windows-build:
|
|
name: Build Windows binaries
|
|
runs-on: windows-2019
|
|
steps:
|
|
- name: Git Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Go
|
|
uses: actions/setup-go@v2
|
|
with:
|
|
go-version: '~1.18.1'
|
|
|
|
- name: Install Ziti CI
|
|
uses: netfoundry/ziti-ci@v1
|
|
|
|
- name: Build and Test
|
|
shell: bash
|
|
run: |
|
|
go install github.com/mitchellh/gox@latest
|
|
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
|
$(go env GOPATH)/bin/gox -cgo -os=windows -arch=amd64 -output=$GOX_OUTPUT ./...
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: windows-release-${{ github.run_id }}
|
|
path: release/
|
|
retention-days: 5
|
|
|
|
linux-build:
|
|
name: Build and Publish Linux Binaries and Docker Image
|
|
runs-on: ubuntu-18.04
|
|
needs: [ mac-os-build, windows-build ]
|
|
outputs:
|
|
ziti-version: ${{ steps.get_version.outputs.ziti-version }}
|
|
steps:
|
|
- name: Git Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Go
|
|
uses: actions/setup-go@v2
|
|
with:
|
|
go-version: '~1.18.1'
|
|
|
|
- name: Install Python
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: '3.7'
|
|
|
|
- name: Install Ziti CI
|
|
uses: netfoundry/ziti-ci@v1
|
|
|
|
- name: Build and Test
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ziti_ci_gpg_key: ${{ secrets.ZITI_CI_GPG_KEY }}
|
|
ziti_ci_gpg_key_id: ${{ secrets.ZITI_CI_GPG_KEY_ID }}
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get -yq install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc-aarch64-linux-gnu
|
|
$(go env GOPATH)/bin/ziti-ci configure-git
|
|
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
|
go install github.com/mitchellh/gox@latest
|
|
$(go env GOPATH)/bin/gox -cgo -os=linux -arch=amd64 -output=$GOX_OUTPUT ./...
|
|
CC=arm-linux-gnueabihf-gcc $(go env GOPATH)/bin/gox -cgo -os=linux -arch=arm -output=$GOX_OUTPUT ./...
|
|
CC=aarch64-linux-gnu-gcc $(go env GOPATH)/bin/gox -cgo -os=linux -arch=arm64 -output=$GOX_OUTPUT ./...
|
|
|
|
- name: Download darwin release artifact
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: darwin-release-${{ github.run_id }}
|
|
path: release/
|
|
|
|
- name: Download windows release artifact
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: windows-release-${{ github.run_id }}
|
|
path: release/
|
|
|
|
- name: Install Jfrog CLI
|
|
uses: jfrog/setup-jfrog-cli@v1
|
|
|
|
# remaining steps in job only run on the upstream repo, not forks
|
|
- name: Publish
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ziti_ci_gpg_key: ${{ secrets.ZITI_CI_GPG_KEY }}
|
|
ziti_ci_gpg_key_id: ${{ secrets.ZITI_CI_GPG_KEY_ID }}
|
|
run: |
|
|
$(go env GOPATH)/bin/ziti-ci tag -v -f version
|
|
$(go env GOPATH)/bin/ziti-ci publish-to-github
|
|
|
|
# only ziti-ci computed version for release branches and {version}-{run_id} for non-release branches
|
|
- name: Compute the Ziti Version String for CI Jobs
|
|
id: get_version
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GITHUB_REF: ${{ github.ref }}
|
|
GITHUB_RUN_ID: ${{ github.run_id }}
|
|
run: |
|
|
ZITI_VERSION="$($(go env GOPATH)/bin/ziti-ci -q get-current-version)"
|
|
# drop the leading 'v', if any
|
|
ZITI_VERSION=${ZITI_VERSION#v}
|
|
if ! [[ "${ZITI_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
# fail the job because we could not obtain the current version from ziti-ci
|
|
echo "ERROR: ZITI_VERSION=${ZITI_VERSION}"
|
|
exit 1
|
|
elif [[ "${GITHUB_REF}" =~ ^refs/heads/(release-v|main$) ]]; then
|
|
# Set output parameters for release branches
|
|
echo "DEBUG: ZITI_VERSION=${ZITI_VERSION}"
|
|
echo ::set-output name=ziti-version::${ZITI_VERSION}
|
|
else
|
|
# Append build / run number for non-release refs
|
|
ZITI_VERSION="${ZITI_VERSION}-${GITHUB_RUN_ID}"
|
|
echo "DEBUG: ZITI_VERSION=${ZITI_VERSION}"
|
|
echo ::set-output name=ziti-version::${ZITI_VERSION}
|
|
fi
|
|
|
|
- name: Publish to Artifactory
|
|
if: ${{ env.JFROG_API_KEY != null && github.repository == 'openziti/ziti' }}
|
|
run: |
|
|
$(go env GOPATH)/bin/ziti-ci publish-to-artifactory
|
|
env:
|
|
JFROG_API_KEY: ${{ secrets.JFROG_API_KEY }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up QEMU
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
uses: docker/setup-qemu-action@master
|
|
with:
|
|
platforms: amd64,arm64,arm
|
|
|
|
- name: Set up Docker BuildKit
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@master
|
|
|
|
- name: Login to Docker Hub
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_API_USER }}
|
|
password: ${{ secrets.DOCKER_HUB_API_TOKEN }}
|
|
|
|
- name: Set up Docker image tags
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
env:
|
|
SNAPSHOT_REPO: openziti/ziti-tunnel
|
|
RELEASE_REPO: netfoundry/ziti-tunnel
|
|
ZITI_VERSION: ${{ steps.get_version.outputs.ziti-version }}
|
|
id: tagprep
|
|
run: |
|
|
# the Docker cross-build only runs on branches main or release-v*
|
|
# where ziti-ci always computes and publishes a new release tag
|
|
DOCKER_TAGS=""
|
|
for REPO in ${SNAPSHOT_REPO} ${RELEASE_REPO}; do
|
|
DOCKER_TAGS+=",${REPO}:${ZITI_VERSION},${REPO}:latest"
|
|
done
|
|
DOCKER_TAGS=${DOCKER_TAGS#,} # drop leading comma char
|
|
echo "DEBUG: DOCKER_TAGS=${DOCKER_TAGS}"
|
|
echo ::set-output name=tags::${DOCKER_TAGS}
|
|
|
|
- name: Build & Push Multi-Platform Container Image to Hub
|
|
if: github.repository_owner == 'openziti' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-v'))
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
builder: ${{ steps.buildx.outputs.name }}
|
|
context: ${{ github.workspace }} # build context is workspace so we can copy artifacts from ./release
|
|
file: ${{ github.workspace }}/ziti-tunnel/docker/Dockerfile.copy # a Dockerfile that does copy instead of fetch
|
|
build-args: | # base dir for copy/add operations should be dir containing Dockerfile
|
|
DOCKER_BUILD_DIR=./ziti-tunnel/docker
|
|
platforms: linux/amd64,linux/arm/v7,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.tagprep.outputs.tags }}
|
|
|
|
# END linux-build-steps
|
|
|
|
smoketest:
|
|
# BEGIN smoketest-job
|
|
#
|
|
# Any event that triggers this main workflow also triggers the smoketest
|
|
#
|
|
needs: linux-build
|
|
name: Call the On-Demand Smoketest Workflow
|
|
uses: ./.github/workflows/jenkins-smoketest.yml
|
|
secrets: inherit
|
|
with:
|
|
ziti-version: ${{ needs.linux-build.outputs.ziti-version }}
|