Skip to content
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
50 changes: 38 additions & 12 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@ concurrency:

jobs:
build:
if: github.repository == 'apache/cloudstack-kubernetes-provider' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
if: github.repository == 'apache/cloudstack-kubernetes-provider'
runs-on: ubuntu-22.04
steps:
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set Docker repository name
run: echo "DOCKER_REPOSITORY=apache" >> $GITHUB_ENV

Expand All @@ -57,8 +50,41 @@ jobs:
- name: Set Docker image FULL TAG
run: echo "FULL_TAG=$(if [ "${{ secrets.DOCKER_REGISTRY }}" = "" ];then echo ${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};else echo ${{ secrets.DOCKER_REGISTRY }}/${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};fi)" >> $GITHUB_ENV

- name: Build the Docker image for cloudstack-kubernetes-provider
run: docker build . --file Dockerfile --tag ${FULL_TAG}
- name: Check if should push
id: should_push
run: |
if [ "${{ github.event_name }}" != "pull_request" ] || [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
echo "should_push=true" >> $GITHUB_OUTPUT
else
echo "should_push=false" >> $GITHUB_OUTPUT
fi

- name: Push Docker image to Docker Registry
run: docker push ${FULL_TAG}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Registry
if: steps.should_push.outputs.should_push == 'true'
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set cache configuration
id: cache_config
run: |
if [ "${{ steps.should_push.outputs.should_push }}" = "true" ]; then
echo "cache_from=type=registry,ref=${FULL_TAG}-cache" >> $GITHUB_OUTPUT
echo "cache_to=type=registry,ref=${FULL_TAG}-cache,mode=max" >> $GITHUB_OUTPUT
fi

- name: Build and push Docker image for cloudstack-kubernetes-provider (multi-arch)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ steps.should_push.outputs.should_push == 'true' }}
tags: ${{ env.FULL_TAG }}
cache-from: ${{ steps.cache_config.outputs.cache_from }}
cache-to: ${{ steps.cache_config.outputs.cache_to }}
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
# specific language governing permissions and limitations
# under the License.

FROM golang:1.21 as builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
COPY . /go/src/github.com/apache/cloudstack-kubernetes-provider
WORKDIR /go/src/github.com/apache/cloudstack-kubernetes-provider
RUN make clean && CGO_ENABLED=0 GOOS=linux make
RUN make clean && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make

FROM gcr.io/distroless/static:nonroot
COPY --from=builder /go/src/github.com/apache/cloudstack-kubernetes-provider/cloudstack-ccm /app/cloudstack-ccm
Expand Down
Loading