Integrate JS asset build into Golang Dockerfile to ensure consistent builds and deployment process" (#3576)

* SRE Portal build is now incorporated into the RP build process in "make ci-rp"
This commit is contained in:
Shubhadapaithankar 2024-05-22 11:13:17 -07:00 коммит произвёл GitHub
Родитель 335e64a0b7
Коммит 7bf05051f0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 43 добавлений и 28 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -10,4 +10,17 @@
!pkg
!swagger
!test
!vendor
!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

Просмотреть файл

@ -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) .