diff --git a/debian_component_based/emulator-testing.sh b/debian_component_based/emulator-testing.sh new file mode 100755 index 00000000..d94af442 --- /dev/null +++ b/debian_component_based/emulator-testing.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +apt-get update && apt-get install -y lsof + +# Start the server in the background +gcloud beta emulators $1 start --host-port=0.0.0.0:8085 --project=blah & + +# Wait a few seconds for the server to start +sleep 10 + +# Check if the server is listening on the port +if lsof -i :8085 > /dev/null; then + echo "Server started successfully (exiting with code 0)" + kill -9 $(lsof -t -i :8085) + exit 0 +else + echo "Server failed to start" + exit 1 +fi diff --git a/debian_component_based/test-components.sh b/debian_component_based/test-components.sh new file mode 100755 index 00000000..656f52d7 --- /dev/null +++ b/debian_component_based/test-components.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +echo "Checking gsutil version" +gsutil version + +echo "Checking kpt version" +kpt version + +echo "Checking local-extract version" +local-extract --version + +echo "Checking gke-gcloud-auth-plugin version" +gke-gcloud-auth-plugin --version + +echo "Checking bq version" +bq version + +echo "Checking bundled-python version" +/usr/lib/google-cloud-sdk/platform/bundledpythonunix/bin/python --version + +echo "Checking cbt version" +cbt version + +echo "Checking crc checksum for gcloud" +gcloud-crc32c /usr/bin/gcloud + +echo "Checking kubectl version" +kubectl version + +echo "Checking the emulators" +./test-all-emulators.sh diff --git a/debian_component_based/test-dcb-emulators.sh b/debian_component_based/test-dcb-emulators.sh new file mode 100755 index 00000000..c3158df4 --- /dev/null +++ b/debian_component_based/test-dcb-emulators.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +./emulator-testing.sh pubsub +if [ $? -ne 0 ]; then + + echo "Pub/sub emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh datastore +if [ $? -ne 0 ]; then + + echo "Datastore emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh bigtable +if [ $? -ne 0 ]; then + + echo "Bigtable emulator failed to execute." + exit 1 + +fi + diff --git a/emulators/emulator-testing.sh b/emulators/emulator-testing.sh new file mode 100755 index 00000000..d94af442 --- /dev/null +++ b/emulators/emulator-testing.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +apt-get update && apt-get install -y lsof + +# Start the server in the background +gcloud beta emulators $1 start --host-port=0.0.0.0:8085 --project=blah & + +# Wait a few seconds for the server to start +sleep 10 + +# Check if the server is listening on the port +if lsof -i :8085 > /dev/null; then + echo "Server started successfully (exiting with code 0)" + kill -9 $(lsof -t -i :8085) + exit 0 +else + echo "Server failed to start" + exit 1 +fi diff --git a/emulators/test-all-emulators.sh b/emulators/test-all-emulators.sh new file mode 100755 index 00000000..ff65f95f --- /dev/null +++ b/emulators/test-all-emulators.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +./emulator-testing.sh pubsub +if [ $? -ne 0 ]; then + + echo "Pub/sub emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh datastore +if [ $? -ne 0 ]; then + + echo "Datastore emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh firestore +if [ $? -ne 0 ]; then + + echo "Firestore emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh spanner +if [ $? -ne 0 ]; then + + echo "Spanner emulator failed to execute." + exit 1 + +fi + +./emulator-testing.sh bigtable +if [ $? -ne 0 ]; then + + echo "Bigtable emulator failed to execute." + exit 1 + +fi + diff --git a/test-latest.sh b/test-latest.sh new file mode 100755 index 00000000..656f52d7 --- /dev/null +++ b/test-latest.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +echo "Checking gsutil version" +gsutil version + +echo "Checking kpt version" +kpt version + +echo "Checking local-extract version" +local-extract --version + +echo "Checking gke-gcloud-auth-plugin version" +gke-gcloud-auth-plugin --version + +echo "Checking bq version" +bq version + +echo "Checking bundled-python version" +/usr/lib/google-cloud-sdk/platform/bundledpythonunix/bin/python --version + +echo "Checking cbt version" +cbt version + +echo "Checking crc checksum for gcloud" +gcloud-crc32c /usr/bin/gcloud + +echo "Checking kubectl version" +kubectl version + +echo "Checking the emulators" +./test-all-emulators.sh diff --git a/testing/alpine/Dockerfile b/testing/alpine/Dockerfile new file mode 100644 index 00000000..4a52d31f --- /dev/null +++ b/testing/alpine/Dockerfile @@ -0,0 +1,33 @@ +FROM docker:27.4.1 as static-docker-source + +FROM alpine:3.19 +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +ENV PATH /google-cloud-sdk/bin:$PATH +COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker +COPY --from=static-docker-source /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildx +RUN addgroup -g 1000 -S cloudsdk && \ + adduser -u 1000 -S cloudsdk -G cloudsdk +RUN if [ `uname -m` = 'x86_64' ]; then echo -n "x86_64" > /tmp/arch; else echo -n "arm" > /tmp/arch; fi; +RUN ARCH=`cat /tmp/arch` && apk --no-cache upgrade && apk --no-cache add \ + curl \ + python3 \ + py3-crcmod \ + py3-openssl \ + bash \ + libc6-compat \ + openssh-client \ + git \ + gnupg \ + && curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + tar xzf google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + rm google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment docker_image_alpine && \ + gcloud --version && \ + gsutil version && \ + bq version && \ + gcloud-crc32c /google-cloud-sdk/bin/gcloud +RUN git config --system credential.'https://source.developers.google.com'.helper gcloud.sh +VOLUME ["/root/.config"] diff --git a/testing/debian_component_based/Dockerfile b/testing/debian_component_based/Dockerfile new file mode 100644 index 00000000..35f3f9f2 --- /dev/null +++ b/testing/debian_component_based/Dockerfile @@ -0,0 +1,45 @@ +FROM docker:27.4.1 as static-docker-source + +FROM marketplace.gcr.io/google/debian12:latest +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +ENV PATH /google-cloud-sdk/bin:$PATH +COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker +COPY --from=static-docker-source /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildx +RUN groupadd -r -g 1000 cloudsdk && \ + useradd -r -u 1000 -m -s /bin/bash -g cloudsdk cloudsdk +RUN apt-get update -qqy && apt-get -qqy upgrade && apt-get install -qqy \ + curl \ + gcc \ + python3-dev \ + python3-pip \ + python3-crcmod \ + apt-transport-https \ + lsb-release \ + openssh-client \ + git \ + make \ + gnupg \ + openjdk-17-jre-headless +RUN if [ `uname -m` = 'x86_64' ]; then echo -n "x86_64" > /tmp/arch; else echo -n "arm" > /tmp/arch; fi; +RUN ARCH=`cat /tmp/arch` && curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + tar xzf google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + rm google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz +RUN echo -n "app-engine-java app-engine-python alpha beta pubsub-emulator cloud-datastore-emulator app-engine-go bigtable cbt app-engine-python-extras kubectl gke-gcloud-auth-plugin kustomize minikube skaffold kpt local-extract" > /tmp/additional_components +# These components are not available on ARM right now. +RUN if [ `uname -m` = 'x86_64' ]; then echo -n " appctl nomos anthos-auth" >> /tmp/additional_components; fi; +RUN /google-cloud-sdk/install.sh --bash-completion=false --path-update=true --usage-reporting=false \ + --additional-components `cat /tmp/additional_components` && rm -rf /google-cloud-sdk/.install/.backup +RUN git config --system credential.'https://source.developers.google.com'.helper gcloud.sh +VOLUME ["/root/.config", "/root/.kube"] +RUN gcloud config set metrics/environment docker_image_debian_component_based + +COPY test-components.sh /usr/local/bin/test-components.sh +COPY emulator-testing.sh /usr/local/bin/emulator-testing.sh +COPY test-dcb-emulators.sh /usr/local/bin/test-all-emulators.sh + +RUN cd /usr/local/bin && ./test-components.sh +RUN rm /usr/local/bin/emulator-testing.sh +RUN rm /usr/local/bin/test-all-emulators.sh +RUN rm /usr/local/bin/test-components.sh + diff --git a/testing/debian_slim/Dockerfile b/testing/debian_slim/Dockerfile new file mode 100644 index 00000000..10544474 --- /dev/null +++ b/testing/debian_slim/Dockerfile @@ -0,0 +1,36 @@ +FROM docker:27.4.1 as static-docker-source + +FROM marketplace.gcr.io/google/debian12:latest +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker +COPY --from=static-docker-source /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildx +RUN groupadd -r -g 1000 cloudsdk && \ + useradd -r -u 1000 -m -s /bin/bash -g cloudsdk cloudsdk +ARG INSTALL_COMPONENTS +RUN mkdir -p /usr/share/man/man1/ +RUN apt-get update -qqy && apt-get -qqy upgrade && apt-get install -qqy \ + curl \ + gcc \ + python3-dev \ + python3-crcmod \ + python3-pip \ + apt-transport-https \ + lsb-release \ + openssh-client \ + git \ + gnupg && \ + export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ + curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /etc/apt/keyrings/google-cloud-cli.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/google-cloud-cli.gpg] https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \ + apt-get update && apt-get install -y google-cloud-cli=${CLOUD_SDK_VERSION}-0 $INSTALL_COMPONENTS && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment docker_image_slim && \ + gcloud --version && \ + gsutil version && \ + bq version && \ + gcloud-crc32c /usr/bin/gcloud && \ + docker --version +RUN git config --system credential.'https://source.developers.google.com'.helper gcloud.sh +VOLUME ["/root/.config"] diff --git a/testing/emulators/Dockerfile b/testing/emulators/Dockerfile new file mode 100644 index 00000000..c98adb28 --- /dev/null +++ b/testing/emulators/Dockerfile @@ -0,0 +1,41 @@ +# debian12 is used instead of alpine because the cloud bigtable emulator requires glibc. +FROM marketplace.gcr.io/google/debian12:latest + +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +ENV PATH /google-cloud-sdk/bin:$PATH + +RUN groupadd -r -g 1000 cloudsdk && \ + useradd -r -u 1000 -m -s /bin/bash -g cloudsdk cloudsdk + +RUN echo -n "cloud-datastore-emulator cloud-firestore-emulator pubsub-emulator bigtable" > /tmp/additional_components +RUN if [ `uname -m` = 'x86_64' ]; then echo -n " cloud-spanner-emulator" >> /tmp/additional_components; fi; +RUN cat /tmp/additional_components +RUN if [ `uname -m` = 'x86_64' ]; then echo -n "x86_64" > /tmp/arch; else echo -n "arm" > /tmp/arch; fi; + +RUN ARCH=`cat /tmp/arch` && \ + mkdir -p /usr/share/man/man1/ && \ + apt-get update && \ + apt-get -qqy upgrade && \ + apt-get -y install \ + curl \ + python3 \ + python3-crcmod \ + bash \ + openjdk-17-jre-headless && \ + curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + tar xzf google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + rm google-cloud-cli-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment docker_image_emulator && \ + gcloud components install beta `cat /tmp/additional_components` && \ + rm -rf /google-cloud-sdk/.install/.backup/ && \ + find /google-cloud-sdk/ -name "__pycache__" -type d | xargs -n 1 rm -rf && \ + rm -rf /var/lib/apt/lists tmp/* + +COPY emulator-testing.sh /usr/local/bin/emulator-testing.sh +COPY test-all-emulators.sh /usr/local/bin/test-all-emulators.sh +RUN cd /usr/local/bin && ./test-all-emulators.sh +RUN rm /usr/local/bin/emulator-testing.sh +RUN rm /usr/local/bin/test-all-emulators.sh diff --git a/testing/latest/Dockerfile b/testing/latest/Dockerfile new file mode 100644 index 00000000..a5cf7626 --- /dev/null +++ b/testing/latest/Dockerfile @@ -0,0 +1,56 @@ +FROM docker:27.4.1 as static-docker-source + +FROM marketplace.gcr.io/google/debian12:latest +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker +COPY --from=static-docker-source /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildx +RUN groupadd -r -g 1000 cloudsdk && \ + useradd -r -u 1000 -m -s /bin/bash -g cloudsdk cloudsdk +RUN apt-get update -qqy && apt-get -qqy upgrade && apt-get install -qqy \ + curl \ + python3-dev \ + python3-crcmod \ + apt-transport-https \ + lsb-release \ + openssh-client \ + git \ + make \ + gnupg && \ + export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ + echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ + apt-get update && \ + apt-get install -y google-cloud-cli=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-app-engine-python=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-app-engine-python-extras=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-app-engine-java=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-app-engine-go=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-datastore-emulator=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-pubsub-emulator=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-bigtable-emulator=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-firestore-emulator=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-spanner-emulator=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-cbt=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-kpt=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-local-extract=${CLOUD_SDK_VERSION}-0 \ + google-cloud-cli-gke-gcloud-auth-plugin=${CLOUD_SDK_VERSION}-0 \ + kubectl && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment docker_image_latest && \ + gcloud --version && \ + docker --version && kubectl version --client +RUN apt-get install -qqy \ + gcc \ + python3-pip +RUN git config --system credential.'https://source.developers.google.com'.helper gcloud.sh +COPY emulators/emulator-testing.sh /usr/local/bin/emulator-testing.sh +COPY emulators/test-all-emulators.sh /usr/local/bin/test-all-emulators.sh +COPY test-latest.sh /usr/local/bin/test-latest.sh +RUN cd /usr/local/bin && ./test-latest.sh +RUN rm /usr/local/bin/emulator-testing.sh +RUN rm /usr/local/bin/test-all-emulators.sh +RUN rm /usr/local/bin/test-latest.sh + +VOLUME ["/root/.config", "/root/.kube"] diff --git a/testing/stable/Dockerfile b/testing/stable/Dockerfile new file mode 100644 index 00000000..ac3531c8 --- /dev/null +++ b/testing/stable/Dockerfile @@ -0,0 +1,47 @@ +FROM marketplace.gcr.io/google/debian12:latest as build_image + +ARG CLOUD_SDK_VERSION +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +ARG INSTALL_COMPONENTS + +RUN apt-get update -qqy && apt-get -qqy upgrade && \ + apt-get install -qqy \ + curl \ + ca-certificates \ + lsb-release \ + gnupg && \ + export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ + echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg && \ + apt-get update && \ + apt-get install -y --no-install-recommends google-cloud-cli=${CLOUD_SDK_VERSION}-0 $INSTALL_COMPONENTS &&\ + rm -rf /root/.cache/pip/ && \ + find / -name '*.pyc' -delete && \ + find / -name '*__pycache__*' -delete +FROM marketplace.gcr.io/google/debian12:latest as runtime_image +COPY --from=build_image /usr/lib/google-cloud-sdk /usr/lib/google-cloud-sdk + +ENV PATH=$PATH:/usr/lib/google-cloud-sdk/bin +# Create a non-root user +RUN groupadd -r -g 1000 cloudsdk && \ + useradd -r -u 1000 -m -s /bin/bash -g cloudsdk cloudsdk +RUN if [ `uname -m` = 'x86_64' ]; then echo -n "x86_64" > /tmp/arch; else echo -n "arm" > /tmp/arch && \ + apt-get update -qqy && apt-get -qqy upgrade && apt-get install -qqy \ + python3-dev \ + python3-crcmod; fi; +RUN gcloud --version && \ + gsutil version && \ + bq version && \ + gcloud-crc32c /usr/lib/google-cloud-sdk/bin/gcloud && \ + gcloud config set core/disable_usage_reporting false && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment docker_image_stable && \ + rm -rf /root/.cache/pip/ && \ + find / -name '*.pyc' -delete && \ + find / -name '*__pycache__*' -exec rm -r {} \+ +VOLUME ["/root/.config"] + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +# Set the entrypoint to the preprocessing script +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]