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

[v410-alpha1] PE-2796 fix build opensuse image in proxy env (#72) #73

Merged
merged 1 commit into from
Oct 17, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ config.yaml
content-*/*
*.arg
.idea

.DS_Store
20 changes: 17 additions & 3 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ build-provider-images-fips:
BUILD +provider-image --K8S_VERSION=1.27.2
END

download-etcdctl:
base-alpine:
FROM alpine
ARG TARGETOS
ARG TARGETARCH
IF [ ! -z $PROXY_CERT_PATH ]
COPY sc.crt /etc/ssl/certs
RUN update-ca-certificates
END
RUN apk add curl

download-etcdctl:
FROM +base-alpine
RUN curl --retry 5 -Ls https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-${TARGETARCH}.tar.gz | tar -xvzf - --strip-components=1 etcd-${ETCD_VERSION}-linux-${TARGETARCH}/etcdctl && \
chmod +x etcdctl
SAVE ARTIFACT etcdctl
Expand Down Expand Up @@ -225,13 +232,14 @@ base-image:
END

IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ]
RUN apt update && \
apt install --no-install-recommends zstd vim -y
# Add proxy certificate if present
IF [ ! -z $PROXY_CERT_PATH ]
COPY sc.crt /etc/ssl/certs
RUN update-ca-certificates
END

RUN apt update && \
apt install --no-install-recommends zstd vim -y
IF [ "$UPDATE_KERNEL" = "false" ]
RUN if dpkg -l linux-image-generic-hwe-20.04 > /dev/null; then apt-mark hold linux-image-generic-hwe-20.04; fi && \
if dpkg -l linux-image-generic-hwe-22.04 > /dev/null; then apt-mark hold linux-image-generic-hwe-22.04; fi && \
Expand All @@ -252,6 +260,12 @@ base-image:

# IF OS Type is Opensuse
ELSE IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] && [ "$ARCH" = "amd64" ]
# Add proxy certificate if present
IF [ ! -z $PROXY_CERT_PATH ]
COPY sc.crt /usr/share/pki/trust/anchors
RUN update-ca-certificates
END

IF [ "$UPDATE_KERNEL" = "false" ]
RUN zypper al kernel-de*
END
Expand Down
11 changes: 6 additions & 5 deletions earthly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ function build_with_proxy() {
export HTTPS_PROXY=$HTTPS_PROXY
gitconfig=$(envsubst <.gitconfig.template | base64 | tr -d '\n')
# cleanup any previous earthly-buildkitd
if [ "$( docker container inspect -f '{{.State.Running}}' earthly-buildkitd )" = "true" ]; then
if [ "$(docker container inspect -f '{{.State.Running}}' earthly-buildkitd)" = "true" ]; then
docker stop earthly-buildkitd
fi
# start earthly buildkitd
docker run -d --privileged --name earthly-buildkitd -v /var/run/docker.sock:/var/run/docker.sock --rm -t -e BUILDKIT_TCP_TRANSPORT_ENABLED=true -e http_proxy=$HTTP_PROXY -e https_proxy=$HTTPS_PROXY -e HTTPS_PROXY=$HTTPS_PROXY -e HTTP_PROXY=$HTTP_PROXY -e NO_PROXY=$NO_PROXY -e no_proxy=$no_proxy -e EARTHLY_GIT_CONFIG=$gitconfig -v "$PROXY_CERT_PATH:/usr/local/share/ca-certificates/sc.crt:ro" -v earthly-tmp:/tmp/earthly:rw -p 8372:8372 gcr.io/spectro-images-public/earthly/buildkitd:$EARTHLY_VERSION
docker run -d --privileged --name earthly-buildkitd -v /var/run/docker.sock:/var/run/docker.sock --rm -t -e GLOBAL_CONFIG="$global_config" -e BUILDKIT_TCP_TRANSPORT_ENABLED=true -e http_proxy=$HTTP_PROXY -e https_proxy=$HTTPS_PROXY -e HTTPS_PROXY=$HTTPS_PROXY -e HTTP_PROXY=$HTTP_PROXY -e NO_PROXY=$NO_PROXY -e no_proxy=$no_proxy -e EARTHLY_GIT_CONFIG=$gitconfig -v "$PROXY_CERT_PATH:/usr/local/share/ca-certificates/sc.crt:ro" -v earthly-tmp:/tmp/earthly:rw -p 8372:8372 gcr.io/spectro-images-public/earthly/buildkitd:$EARTHLY_VERSION
# Update the CA certificates in the container
docker exec -it earthly-buildkitd update-ca-certificates

# Run Earthly in Docker to create artifacts Variables are passed from the .arg file
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -e EARTHLY_BUILDKIT_HOST=tcp://0.0.0.0:8372 -e BUILDKIT_TLS_ENABLED=false -v "$(pwd)":/workspace -v "$PROXY_CERT_PATH:/workspace/sc.crt:ro" gcr.io/spectro-images-public/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -e GLOBAL_CONFIG="$global_config" -e EARTHLY_BUILDKIT_HOST=tcp://0.0.0.0:8372 -e BUILDKIT_TLS_ENABLED=false -v "$(pwd)":/workspace -v "$PROXY_CERT_PATH:/workspace/sc.crt:ro" gcr.io/spectro-images-public/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
}

function build_without_proxy() {
# Run Earthly in Docker to create artifacts Variables are passed from the .arg file
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -v "$(pwd)":/workspace gcr.io/spectro-images-public/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -e GLOBAL_CONFIG="$global_config "-v "$(pwd)":/workspace gcr.io/spectro-images-public/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
}

global_config="{disable_analytics: true}"
PE_VERSION=$(git describe --abbrev=0 --tags)
EARTHLY_VERSION=v0.7.4
source .arg
Expand Down Expand Up @@ -50,7 +51,7 @@ if [ $? -ne 0 ]; then
fi
# Cleanup builder helper images.
docker rmi gcr.io/spectro-images-public/earthly/earthly:$EARTHLY_VERSION
if [ "$( docker container inspect -f '{{.State.Running}}' earthly-buildkitd )" = "true" ]; then
if [ "$(docker container inspect -f '{{.State.Running}}' earthly-buildkitd)" = "true" ]; then
docker stop earthly-buildkitd
fi
docker rmi gcr.io/spectro-images-public/earthly/buildkitd:$EARTHLY_VERSION
Expand Down