diff --git a/Dockerfile.ci-portal b/Dockerfile.ci-portal deleted file mode 100644 index d54d1af07..000000000 --- a/Dockerfile.ci-portal +++ /dev/null @@ -1,13 +0,0 @@ -ARG REGISTRY - -FROM ${REGISTRY}/ubi8/nodejs-16 AS portal-base -WORKDIR /build/portal/v2 -USER root - -FROM portal-base AS portal-build -COPY /portal/v2/package*.json ./ -RUN npm ci -RUN npm audit --omit=dev -COPY /portal/v2/ ./ -RUN npm run lint -RUN npm run build \ No newline at end of file diff --git a/Dockerfile.ci-rp b/Dockerfile.ci-rp index 4750d88bb..23ee37330 100644 --- a/Dockerfile.ci-rp +++ b/Dockerfile.ci-rp @@ -2,20 +2,38 @@ ARG REGISTRY ARG VERSION ############################################################################### +# Stage 1: Build the SRE Portal Assets # builder is responsible for all compilation and validation of the RP ############################################################################### -FROM ${REGISTRY}/ubi8/go-toolset:1.20.12-5 as builder +FROM ${REGISTRY}/ubi8/nodejs-16 as portal-build +WORKDIR /build/portal/v2 +USER root + +# Copying package files and installing dependencies +COPY portal/v2/package*.json ./ +RUN npm ci +RUN npm audit --omit=dev # Run audit without dev dependencies + +# Copying the rest of the source and build +COPY --chown=root:root portal/v2/ ./ +RUN npm run lint && npm run build + +############################################################################### +# Stage 2: Compile the Golang RP code +############################################################################### +FROM ${REGISTRY}/ubi8/go-toolset:1.20.12-5 AS builder USER root WORKDIR /app -# golang config +# golang config and build steps ENV GOPATH=/root/go ENV GOFLAGS="-tags=containers_image_openpgp,exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper" -# install general build tools -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.56.2 +# Install golangci-lint and verify +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.56.2 && \ + golangci-lint --version || (echo "golangci-lint not found" && exit 1) -# copy from least changed -> most changed to improve cache hits +# Copy dependencies and source files COPY go.mod go.sum ./ COPY vendor vendor COPY swagger swagger @@ -25,20 +43,21 @@ COPY cmd cmd COPY pkg pkg COPY test test -# lint -RUN golangci-lint run --verbose +# Ensure JS assets are available before generating Go code +COPY --from=portal-build /build/pkg/portal/assets/v2/build /app/pkg/portal/assets/v2/build -# build +# Lint, generate, build, and test +RUN golangci-lint run --verbose RUN go generate ./... RUN go build -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=${VERSION}" ./cmd/aro RUN go test ./test/e2e/... -tags e2e,codec.safe -c -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=${VERSION}" -o e2e.test -# test +# Additional tests RUN ARO_RUN_PKI_TESTS=nope go run gotest.tools/gotestsum@v1.11.0 --format pkgname --junitfile report.xml -- -coverprofile=cover.out ./... RUN hack/fips/validate-fips.sh ./aro ############################################################################### -# final is our slim image with minimal layers and tools +# Stage 3: final is our slim image with minimal layers and tools ############################################################################### FROM ${REGISTRY}/ubi8/ubi-minimal AS final RUN microdnf update && microdnf clean all diff --git a/Dockerfile.ci-rp.dockerignore b/Dockerfile.ci-rp.dockerignore index a984a1402..052c75c86 100644 --- a/Dockerfile.ci-rp.dockerignore +++ b/Dockerfile.ci-rp.dockerignore @@ -10,4 +10,17 @@ !pkg !swagger !test -!vendor \ No newline at end of file +!vendor + +# Ignore locally built NPM artifacts - using new automated process +pkg/portal/assets/v2/build + +# Allow files and directories for JavaScript build +!portal/v2/package*.json +!portal/v2/src +!portal/v2/public +!portal/v2/config-overrides.js +!portal/v2/tsconfig.json +!portal/v2/.eslintrc.yml +!portal/v2/.npmrc + diff --git a/Makefile b/Makefile index a0953075d..e5b53a309 100644 --- a/Makefile +++ b/Makefile @@ -79,9 +79,6 @@ client: generate ci-rp: fix-macos-vendor docker build . -f Dockerfile.ci-rp --ulimit=nofile=4096:4096 --build-arg REGISTRY=$(REGISTRY) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE) -ci-portal: - docker build . -f Dockerfile.ci-portal --build-arg REGISTRY=$(REGISTRY) --no-cache=$(NO_CACHE) - # TODO: hard coding dev-config.yaml is clunky; it is also probably convenient to # override COMMIT. deploy: @@ -123,7 +120,6 @@ generate-kiota: init-contrib: install -v hack/git/hooks/* .git/hooks/ - image-aro-multistage: docker build --platform=linux/amd64 --network=host --no-cache -f Dockerfile.aro-multistage -t $(ARO_IMAGE) --build-arg REGISTRY=$(REGISTRY) .