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

Consolidate dockerfiles #154

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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'
26 changes: 24 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# 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


mjholder marked this conversation as resolved.
Show resolved Hide resolved
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.

32 changes: 2 additions & 30 deletions build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,15 @@ 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
Loading