Skip to content

Commit

Permalink
Merge pull request #154 from mjholder/consolidate-dockerfiles
Browse files Browse the repository at this point in the history
Consolidate dockerfiles
  • Loading branch information
adamrdrew authored Mar 1, 2024
2 parents e611f0c + 792354d commit 188490c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 60 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/platsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ jobs:
# dockerfile_name: 'Dockerfile.main'
base_image_build: true
# base_dockerfile_path: './test'
base_dockerfile_name: 'Dockerfile.base'
build_arg: '--build-arg BASE_IMAGE="localbuild/baseimage:latest"'
base_dockerfile_name: 'Dockerfile'
25 changes: 23 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Build the manager binary
ARG BASE_IMAGE=
FROM $BASE_IMAGE as builder
FROM registry.access.redhat.com/ubi8/go-toolset:1.19.13-2.1698062273 as base

WORKDIR /workspace

COPY go.mod go.mod
COPY go.sum go.sum

RUN go mod download

COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

USER 0

RUN CGO_ENABLED=0 GOOS=linux go build -o manager main.go

RUN rm main.go
RUN rm -rf api
RUN rm -rf controllers

# Build the manager binary
FROM base as builder

WORKDIR /workspace

Expand Down
23 changes: 0 additions & 23 deletions Dockerfile.base

This file was deleted.

35 changes: 2 additions & 33 deletions build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,18 @@ fi
DOCKER_CONF="$PWD/.docker"
mkdir -p "$DOCKER_CONF"




docker login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io
docker login -u="$RH_REGISTRY_USER" -p="$RH_REGISTRY_TOKEN" registry.redhat.io

### Start base image build and push
BASE_TAG=`cat go.mod go.sum Dockerfile.base | sha256sum | head -c 8`
BASE_IMG=quay.io/cloudservices/frontend-operator-build-base:$BASE_TAG
RESPONSE=$( \
curl -Ls -H "Authorization: Bearer $QUAY_TOKEN" \
"https://quay.io/api/v1/repository/cloudservices/frontend-operator-build-base/tag/?specificTag=$BASE_TAG" \
)
echo "received HTTP response: $RESPONSE"
# find all non-expired tags
VALID_TAGS_LENGTH=$(echo $RESPONSE | jq '[ .tags[] | select(.end_ts == null) ] | length')

if [[ "$VALID_TAGS_LENGTH" -eq 0 ]]; then
# Check if the multiarchbuilder exists
if docker buildx ls | grep -q "multiarchbuilder"; then
docker buildx use multiarchbuilder
echo "Using multiarchbuilder for buildx"
# Multi-architecture build
docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile.base -t "${BASE_IMG}" --push .
else
echo "Falling back to standard build and push"
# Standard build and push
docker build -t "${BASE_IMG}" -f Dockerfile.base
docker push "${BASE_IMG}"
fi
fi
#### End


# Check if the multiarchbuilder exists
if docker buildx ls | grep -q "multiarchbuilder"; then
docker buildx use multiarchbuilder
echo "Using multiarchbuilder for buildx"
# Multi-architecture build
docker buildx build --platform linux/amd64,linux/arm64 --build-arg BASE_IMAGE="${BASE_IMG}" -t "${IMAGE}:${IMAGE_TAG}" --push .
docker buildx build --platform linux/amd64,linux/arm64 -t "${IMAGE}:${IMAGE_TAG}" --push .
else
echo "Falling back to standard build and push"
# Standard build and push
docker build -t "${IMAGE}:${IMAGE_TAG}" --build-arg BASE_IMAGE="${BASE_IMG}" .
docker build -t "${IMAGE}:${IMAGE_TAG}" .
docker push "${IMAGE}:${IMAGE_TAG}"
fi

0 comments on commit 188490c

Please sign in to comment.