ci: add build GitHub action #4
Workflow file for this run
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: | |
push: | |
branches: | |
- master | |
- v* | |
tags: | |
- v* | |
pull_request: | |
jobs: | |
build: | |
name: Build images | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets | |
container: | |
image: rancher/dapper:v0.6.0 | |
steps: | |
# Git is not in Dapper container image. Add it manually for dirty check. | |
- name: Add Git | |
run: apk add -U git | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Declare branch | |
run: | | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" | |
# For multi-platform support | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Build binaries | |
- name: Run dapper ci | |
run: dapper ci | |
- name: Copy bin folder to package | |
run: | | |
cp -r ./bin/* ./package/ | |
- name: "Read some Secrets" | |
uses: rancher-eio/read-vault-secrets@main | |
with: | |
secrets: | | |
secret/data/github/repo/${{ github.repository }}/dockerhub/credentials username | DOCKER_USERNAME ; | |
secret/data/github/repo/${{ github.repository }}/dockerhub/credentials password | DOCKER_PASSWORD | |
- name: "Use those Secrets" | |
run: | | |
echo "${{ env.DOCKER_USERNAME }} | |
- name: Login to Docker Hub | |
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
# rancher/terraform-provider-harvester image | |
- name: docker-publish | |
if: ${{ startsWith(github.ref, 'refs/heads/') }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: package/ | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: rancher/terraform-provider-harvester:${{ env.branch }}-head | |
file: package/Dockerfile | |
- name: docker-publish-with-tag | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: package/ | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: rancher/terraform-provider-harvester:${{ github.ref_name }} | |
file: package/Dockerfile | |
build-args: | | |
VERSION=${{ github.ref_name }} |