From ed20ad76cee14a0e1d3fa97a07cc10df9c5b1f79 Mon Sep 17 00:00:00 2001 From: mattgogerly Date: Tue, 28 Nov 2023 20:26:58 +0000 Subject: [PATCH] feat(java17): use JRE17, run tests on JRE17, compile with JDK11 --- .github/workflows/build.yml | 25 +++++++ .github/workflows/pr.yml | 20 +++++ .github/workflows/release.yml | 25 +++++++ Dockerfile.java11.slim | 60 +++++++++++++++ Dockerfile.java11.ubuntu | 57 ++++++++++++++ Dockerfile.slim | 2 +- Dockerfile.ubuntu | 2 +- build.gradle | 11 +++ .../jobs/local/JobExecutorLocalSpec.groovy | 75 +++++++++---------- .../oracle/OCIBakeHandlerSpec.groovy | 2 +- .../controllers/BakeryControllerSpec.groovy | 2 +- 11 files changed, 239 insertions(+), 42 deletions(-) create mode 100644 Dockerfile.java11.slim create mode 100644 Dockerfile.java11.ubuntu diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9fdf93ed9..a935ee321 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,3 +72,28 @@ jobs: tags: | "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-unvalidated-ubuntu" "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-unvalidated-ubuntu" + - name: Build and publish slim JRE 11 container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.slim + platforms: linux/amd64,linux/arm64 + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-slim" + - name: Build and publish ubuntu JRE 11 container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.ubuntu + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest-java11-unvalidated-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-ubuntu" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 43b3670f1..34b327aa3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -51,3 +51,23 @@ jobs: tags: | "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-ubuntu" "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-ubuntu" + - name: Build slim JRE 11 container image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.slim + platforms: linux/amd64,linux/arm64 + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-slim" + - name: Build ubuntu JRE 11 container image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.ubuntu + platforms: linux/amd64,linux/arm64 + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest-java11-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}-java11-ubuntu" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f4617ce16..4dfe66aa9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -115,6 +115,31 @@ jobs: tags: | "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-unvalidated-ubuntu" "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-unvalidated-ubuntu" + - name: Build and publish slim JRE 11 container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.slim + platforms: linux/amd64,linux/arm64 + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated-slim" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-slim" + - name: Build and publish ubuntu JRE 11 container image + # Only run this on repositories in the 'spinnaker' org, not on forks. + if: startsWith(github.repository, 'spinnaker/') + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.java11.ubuntu + platforms: linux/amd64,linux/arm64 + push: true + tags: | + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-java11-unvalidated-ubuntu" + "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-ubuntu" - name: Create release if: steps.release_info.outputs.SKIP_RELEASE == 'false' uses: softprops/action-gh-release@v1 diff --git a/Dockerfile.java11.slim b/Dockerfile.java11.slim new file mode 100644 index 000000000..759d909b0 --- /dev/null +++ b/Dockerfile.java11.slim @@ -0,0 +1,60 @@ +FROM alpine:3.16 +LABEL maintainer="sig-platform@spinnaker.io" + +ENV KUSTOMIZE_VERSION=3.8.6 +ENV KUSTOMIZE4_VERSION=4.5.5 +ENV PACKER_VERSION=1.8.1 +ENV HELMFILE_VERSION=0.153.1 + + +ARG TARGETARCH + +WORKDIR /packer + +RUN apk --no-cache add --update bash wget curl openssl openjdk11-jre git openssh-client && \ + wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ + unzip packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ + rm packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip + +ENV PATH "/packer:$PATH" + +# Install Helm 3 +RUN wget https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get-helm-3 && \ + chmod +x get-helm-3 && \ + ./get-helm-3 && \ + rm get-helm-3 && \ + mv /usr/local/bin/helm /usr/local/bin/helm3 + +# Install Helm 2 +RUN wget https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get && \ + chmod +x get && \ + ./get --version v2.17.0 && \ + rm get + +RUN mkdir kustomize && \ + curl -s -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C kustomize/ && \ + mv ./kustomize/kustomize /usr/local/bin/kustomize && \ + rm -rf ./kustomize + +RUN mkdir kustomize && \ + curl -s -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE4_VERSION}/kustomize_v${KUSTOMIZE4_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C kustomize/ && \ + mv ./kustomize/kustomize /usr/local/bin/kustomize4 && \ + rm -rf ./kustomize + +RUN mkdir helmfile && \ + curl -s -L https://github.com/helmfile/helmfile/releases/download/v${HELMFILE_VERSION}/helmfile_${HELMFILE_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C helmfile/ && \ + mv ./helmfile/helmfile /usr/local/bin/helmfile && \ + rm -rf ./helmfile + +RUN addgroup -S -g 10111 spinnaker +RUN adduser -S -G spinnaker -u 10111 spinnaker +COPY rosco-web/build/install/rosco /opt/rosco +COPY rosco-web/config /opt/rosco +COPY halconfig/packer /opt/rosco/config/packer +RUN mkdir -p /opt/rosco/plugins && chown -R spinnaker:nogroup /opt/rosco/plugins +USER spinnaker +CMD ["/opt/rosco/bin/rosco"] + diff --git a/Dockerfile.java11.ubuntu b/Dockerfile.java11.ubuntu new file mode 100644 index 000000000..080147d92 --- /dev/null +++ b/Dockerfile.java11.ubuntu @@ -0,0 +1,57 @@ +FROM ubuntu:bionic +LABEL maintainer="sig-platform@spinnaker.io" + +ENV KUSTOMIZE_VERSION=3.8.6 +ENV KUSTOMIZE4_VERSION=4.5.5 +ENV PACKER_VERSION=1.8.1 +ENV HELMFILE_VERSION=0.153.1 + +ARG TARGETARCH + +WORKDIR /packer + +RUN apt-get update && apt-get -y install openjdk-11-jre-headless wget unzip curl git openssh-client && \ + wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ + unzip packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ + rm packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip + +ENV PATH "/packer:$PATH" + +# Install Helm 3 +RUN wget https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get-helm-3 && \ + chmod +x get-helm-3 && \ + ./get-helm-3 && \ + rm get-helm-3 && \ + mv /usr/local/bin/helm /usr/local/bin/helm3 + +# Install Helm 2 +RUN wget https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get && \ + chmod +x get && \ + ./get --version v2.17.0 && \ + rm get + +RUN mkdir kustomize && \ + curl -s -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C kustomize/ && \ + mv ./kustomize/kustomize /usr/local/bin/kustomize && \ + rm -rf ./kustomize + +RUN mkdir kustomize && \ + curl -s -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE4_VERSION}/kustomize_v${KUSTOMIZE4_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C kustomize/ && \ + mv ./kustomize/kustomize /usr/local/bin/kustomize4 && \ + rm -rf ./kustomize + +RUN mkdir helmfile && \ + curl -s -L https://github.com/helmfile/helmfile/releases/download/v${HELMFILE_VERSION}/helmfile_${HELMFILE_VERSION}_linux_${TARGETARCH}.tar.gz|\ + tar xvz -C helmfile/ && \ + mv ./helmfile/helmfile /usr/local/bin/helmfile && \ + rm -rf ./helmfile + +RUN adduser --system --uid 10111 --group spinnaker +COPY rosco-web/build/install/rosco /opt/rosco +COPY rosco-web/config /opt/rosco +COPY halconfig/packer /opt/rosco/config/packer +RUN mkdir -p /opt/rosco/plugins && chown -R spinnaker:nogroup /opt/rosco/plugins +USER spinnaker +CMD ["/opt/rosco/bin/rosco"] diff --git a/Dockerfile.slim b/Dockerfile.slim index 759d909b0..c567e608b 100644 --- a/Dockerfile.slim +++ b/Dockerfile.slim @@ -11,7 +11,7 @@ ARG TARGETARCH WORKDIR /packer -RUN apk --no-cache add --update bash wget curl openssl openjdk11-jre git openssh-client && \ +RUN apk --no-cache add --update bash wget curl openssl openjdk17-jre git openssh-client && \ wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ unzip packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ rm packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index 080147d92..98b7810dd 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -10,7 +10,7 @@ ARG TARGETARCH WORKDIR /packer -RUN apt-get update && apt-get -y install openjdk-11-jre-headless wget unzip curl git openssh-client && \ +RUN apt-get update && apt-get -y install openjdk-17-jre-headless wget unzip curl git openssh-client && \ wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ unzip packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip && \ rm packer_${PACKER_VERSION}_linux_${TARGETARCH}.zip diff --git a/build.gradle b/build.gradle index 47f38b013..63fb4a60b 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,17 @@ subprojects { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8187' } } + + tasks.withType(JavaCompile).configureEach { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(11) + } + } + tasks.withType(Test).configureEach { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + } + } } defaultTasks ':rosco-web:run' diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/jobs/local/JobExecutorLocalSpec.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/jobs/local/JobExecutorLocalSpec.groovy index 102720379..0fe740268 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/jobs/local/JobExecutorLocalSpec.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/jobs/local/JobExecutorLocalSpec.groovy @@ -3,7 +3,6 @@ package com.netflix.spinnaker.rosco.jobs.local import com.netflix.spectator.api.DefaultRegistry import com.netflix.spinnaker.rosco.api.BakeStatus import com.netflix.spinnaker.rosco.jobs.JobRequest -import com.netflix.spinnaker.rosco.jobs.JobExecutor import com.netflix.spinnaker.rosco.providers.util.TestDefaults import spock.lang.Specification import spock.lang.Subject @@ -11,43 +10,43 @@ import spock.lang.Unroll class JobExecutorLocalSpec extends Specification implements TestDefaults { - private static final String BASH_SCRIPT = '''\ - for i in {1..5}; do - echo "Output $i" - sleep 0.1 - echo "Error $i" >&2 - sleep 0.1 - done - echo "Final output" - '''.stripIndent() - private static final String EXPECTED_OUTPUT = '''\ - Output 1 - Output 2 - Output 3 - Output 4 - Output 5 - Final output - '''.stripIndent() - private static final String EXPECTED_LOGS = '''\ - Error 1 - Error 2 - Error 3 - Error 4 - Error 5 - '''.stripIndent() - private static final String COMBINED_OUTPUT = '''\ - Output 1 - Error 1 - Output 2 - Error 2 - Output 3 - Error 3 - Output 4 - Error 4 - Output 5 - Error 5 - Final output - '''.stripIndent() + private static final String BASH_SCRIPT = """\ +for i in {1..5}; do + echo "Output \$i" + sleep 0.1 + echo "Error \$i" >&2 + sleep 0.1 +done +echo "Final output" +""" + private static final String EXPECTED_OUTPUT = """\ +Output 1 +Output 2 +Output 3 +Output 4 +Output 5 +Final output +""" + private static final String EXPECTED_LOGS = """\ +Error 1 +Error 2 +Error 3 +Error 4 +Error 5 +""" + private static final String COMBINED_OUTPUT = """\ +Output 1 +Error 1 +Output 2 +Error 2 +Output 3 +Error 3 +Output 4 +Error 4 +Output 5 +Error 5 +Final output +""" @Unroll void 'job executor runs command and captures stdout and stderr with combineStdOutAndErr set to #combineStdOutAndErr'() { diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/oracle/OCIBakeHandlerSpec.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/oracle/OCIBakeHandlerSpec.groovy index 3a236b8ef..00005a6c4 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/oracle/OCIBakeHandlerSpec.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/oracle/OCIBakeHandlerSpec.groovy @@ -247,7 +247,7 @@ class OCIBakeHandlerSpec extends Specification implements TestDefaults { then: with(options) { cloudProvider == 'oracle' - baseImages.size == 2 + baseImages.size() == 2 baseImages[0].id == 'ubuntu16_04' baseImages[1].id == 'centos_7' } diff --git a/rosco-web/src/test/groovy/com/netflix/spinnaker/rosco/controllers/BakeryControllerSpec.groovy b/rosco-web/src/test/groovy/com/netflix/spinnaker/rosco/controllers/BakeryControllerSpec.groovy index 7374fd36d..d4f2e83c6 100644 --- a/rosco-web/src/test/groovy/com/netflix/spinnaker/rosco/controllers/BakeryControllerSpec.groovy +++ b/rosco-web/src/test/groovy/com/netflix/spinnaker/rosco/controllers/BakeryControllerSpec.groovy @@ -720,7 +720,7 @@ class BakeryControllerSpec extends Specification { def result = bakeryController.bakeOptions() then: - result.size == 2 + result.size() == 2 result.find { it.cloudProvider == "aws" }.baseImages[0].id == "santa" result.find { it.cloudProvider == "gce" }.baseImages[0].id == "claus"