Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate push_image steps to another job #95

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions .drone.yml

This file was deleted.

61 changes: 41 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,66 @@ on:
pull_request:
jobs:
build:
name: Build images
name: Build binaries
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

# Build binaries
- name: Run ci
run: make ci

- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries_artifact
path: ./bin/*

build_push_image:
name: Build and push images
runs-on: ubuntu-latest
needs: build
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
permissions:
contents: read
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
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries_artifact
path: ./bin/
bk201 marked this conversation as resolved.
Show resolved Hide resolved

# Build binaries
- name: Run dapper ci
run: dapper ci
- name: Copy bin folder to package
- name: Add executable permission
run: |
chmod +x ./bin/*

- name: Copy binaries to package
run: |
cp -r ./bin/* ./package/

- name: Read Secrets
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/harvester/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/harvester/credentials password | DOCKER_PASSWORD

# 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

- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"

- 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 }}
Expand All @@ -64,6 +84,7 @@ jobs:
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
Expand Down
2 changes: 2 additions & 0 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-base:15.5

ARG TARGETPLATFORM
Expand Down
11 changes: 0 additions & 11 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ DOCKERFILE=Dockerfile
rm -rf ./terraform-provider-harvester-*
cp ../bin/terraform-provider-harvester-* .

docker run --privileged --rm tonistiigi/binfmt --install all
buildx create --platform linux/arm64,linux/amd64 --use
buildx ls

# In old docker version, it doesn't support multiple values in --platform with --load.
# So we only load image with current platform.
# Ref: https://github.com/docker/buildx/issues/59#issuecomment-616050491
buildx build \
--build-arg PROVIDER_VERSION=${PROVIDER_VERSION} \
--platform linux/amd64,linux/arm64 \
-f ${DOCKERFILE} -t ${IMAGE} .
buildx build --load \
--build-arg PROVIDER_VERSION=${PROVIDER_VERSION} \
-f ${DOCKERFILE} -t ${IMAGE} .
Expand Down