From 29db5c6a37aca5cc03c6726c78ec94c9ccb5606c Mon Sep 17 00:00:00 2001 From: Aneela Chagarlamudi Date: Fri, 19 Apr 2024 12:35:57 +0200 Subject: [PATCH] Update dockerfile builds --- .dockerignore | 4 ++++ Dockerfile | 10 +++++++++- build_deploy.sh | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..da698880 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +#ignore config directories that might contain secrets +.docker +.kube +.podman \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b91bdf01..625a2e6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,14 @@ FROM registry.redhat.io/rhel8/go-toolset:1.20.12-5.1712568462 AS builder WORKDIR $GOPATH/src/mypackage/myapp/ -COPY . . +COPY go.mod go.mod +COPY go.sum go.sum +COPY Makefile Makefile +COPY main.go main.go +COPY spec spec +COPY pkg pkg +COPY cmd cmd +COPY config config +COPY docs docs ENV GO111MODULE=on USER root RUN go get -d -v diff --git a/build_deploy.sh b/build_deploy.sh index fa1554af..154294be 100755 --- a/build_deploy.sh +++ b/build_deploy.sh @@ -16,7 +16,18 @@ if [[ -z "$RH_REGISTRY_USER" || -z "$RH_REGISTRY_TOKEN" ]]; then exit 1 fi -DOCKER_CONF="$PWD/.docker" +# Create tmp dir to store data in during job run (do NOT store in $WORKSPACE) +export TMP_JOB_DIR=$(mktemp -d -p "$HOME" -t "jenkins-${JOB_NAME}-${BUILD_NUMBER}-XXXXXX") +echo "job tmp dir location: $TMP_JOB_DIR" + +function job_cleanup() { + echo "cleaning up job tmp dir: $TMP_JOB_DIR" + rm -fr $TMP_JOB_DIR +} + +trap job_cleanup EXIT ERR SIGINT SIGTERM + +DOCKER_CONF="$TMP_JOB_DIR/.docker" mkdir -p "$DOCKER_CONF" DOCKER_CONFIG=$DOCKER_CONF docker login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io DOCKER_CONFIG=$DOCKER_CONF docker login -u="$RH_REGISTRY_USER" -p="$RH_REGISTRY_TOKEN" registry.redhat.io