Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: angular-ui build-args support
Browse files Browse the repository at this point in the history
Signed-off-by: Chaz Leong <13462818+cleong14@users.noreply.github.com>
  • Loading branch information
cleong14 committed Jul 24, 2024
1 parent 92a93c7 commit 14a55e5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 44 deletions.
81 changes: 67 additions & 14 deletions angular-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,77 @@
FROM node:alpine AS build
ARG NODE_VERSION=18
ARG ALPINE_VERSION=3.18

FROM --platform=$TARGETPLATFORM artifactory.cloud.cms.gov/docker/library/node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS builder

ARG NODE_VERSION
ENV NODE_VERSION=${NODE_VERSION}

ARG ALPINE_VERSION
ENV ALPINE_VERSION=${ALPINE_VERSION}

ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM}

# `docker build --build-arg ARG1="some ARG1 override" --build-arg ARG2="some ARG2 override"`
ARG ARG1
ENV ARG1=${ARG1:-"default ARG1"}
ARG ARG2
ENV ARG2=${ARG2:-"default ARG2"}

WORKDIR /app
COPY package.json .
RUN npm install

COPY angular.json \
eslint.config.js \
tsconfig.*.json \
lib \
spec \
src /app/

COPY package*.json .

RUN npm ci && npm cache clean --force

COPY package*.json .

RUN npm ci && npm cache clean --force


FROM builder AS build

ARG NODE_VERSION
ENV NODE_VERSION=${NODE_VERSION}

ARG ALPINE_VERSION
ENV ALPINE_VERSION=${ALPINE_VERSION}

ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM}

# `docker build --build-arg ARG1="some ARG1 override" --build-arg ARG2="some ARG2 override"`
ARG ARG1
ENV ARG1=${ARG1:-"default ARG1"}
ARG ARG2
ENV ARG2=${ARG2:-"default ARG2"}

COPY . .

RUN npm run build


FROM node:alpine
FROM --platform=$TARGETPLATFORM artifactory.cloud.cms.gov/docker/library/node:${NODE_VERSION}-alpine${ALPINE_VERSION}

ARG NODE_VERSION
ENV NODE_VERSION=${NODE_VERSION}

ARG ALPINE_VERSION
ENV ALPINE_VERSION=${ALPINE_VERSION}

ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM}

# `docker build --build-arg ARG1="some ARG1 override" --build-arg ARG2="some ARG2 override"`
ARG ARG1
ENV ARG1=${ARG1:-"default ARG1"}
ARG ARG2
ENV ARG2=${ARG2:-"default ARG2"}

WORKDIR /app
COPY --from=build /app /app

EXPOSE 4200
EXPOSE 8888
USER node

COPY --chown=node:node --from=build /app /app

CMD ["npm", "run", "start", "--", "--host", "0.0.0.0"]
88 changes: 58 additions & 30 deletions angular-ui/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
pipeline {
parameters {
string(name: 'platform', defaultValue: 'linux/amd64', description: 'A comma separated list of platforms to build the container image for (e.g., linux/amd64,linux/arm64).')
string(name: 'arch', defaultValue: 'amd64', description: 'Target architecture to build the container image for (e.g., amd64,arm64).')
}

agent {
kubernetes {
yaml """
Expand All @@ -8,34 +13,53 @@ pipeline {
restartPolicy: Never
containers:
- name: build
image: artifactory.cloud.cms.gov/docker/node:18
image: artifactory.cloud.cms.gov/docker/library/node:18-alpine3.18
command: ['tail', '-f', '/dev/null']
imagePullPolicy: Always
env:
- name: TARGETPLATFORM
value: "${params.platform}"
- name: ARCH
value: "${params.arch}"
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/arch: "${params.arch}"
"""
}
}

options {
buildDiscarder(logRotator(daysToKeepStr: '1', numToKeepStr: '10'))
copyArtifactPermission('*');
}

stages {
stage('Build') {
steps {
container('build') {
dir('angular-ui') {
sh 'npm install && npm run build'
sh 'npm ci'
}
}
}
}

stage('Test') {
stage('Test & Lint') {
parallel {
stage('Unit Test') {
steps {
container('build') {
dir('angular-ui') {
sh 'npm run test'
}
}
}
}
// stage('Unit Test') {
// steps {
// container('build') {
// dir('angular-ui') {
// sh 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
// sh 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list'
// sh 'apt-get update'
// sh 'apt-get install google-chrome-stable -y'
// sh 'npm run test:coverage'
// archiveArtifacts artifacts: "coverage/**/*", allowEmptyArchive: true
// }
// }
// }
// }
stage('Lint') {
steps {
container('build') {
Expand All @@ -45,27 +69,31 @@ pipeline {
}
}
}
stage('SAST') {
steps {
script {
def sastParameters = [
string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"),
string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"),
string(name: 'git_commit', value: "${GIT_COMMIT}"),
string(name: 'git_branch', value: "${env.GIT_BRANCH}"),
]

if (env.CHANGE_ID) {
sastParameters.add(string(name: 'git_change_id', value: "${env.CHANGE_ID}"))
}

build(job: 'Angular UI SAST', wait: true, propagate: true, parameters: sastParameters)
}
}
}
}
}

// stage('SAST') {
// steps {
// script {
// def sastParameters = [
// string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"),
// string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"),
// string(name: 'git_commit', value: "${GIT_COMMIT}"),
// string(name: 'git_branch', value: "${env.GIT_BRANCH}"),
// string(name: 'copy_artifacts_job_name', value: "${env.JOB_NAME}"),
// string(name: 'copy_artifacts_build_number', value: "${env.BUILD_NUMBER}"),
// string(name: 'copy_artifacts_filter', value: 'coverage/**/*')
// ]
//
// if (env.CHANGE_ID) {
// sastParameters.add(string(name: 'git_change_id', value: "${env.CHANGE_ID}"))
// }
//
// build(job: 'Angular UI SAST', wait: true, propagate: true, parameters: sastParameters)
// }
// }
// }

stage('Delivery') {
steps {
build(job: 'Angular UI Delivery', wait: true, propagate: true, parameters: [
Expand Down

0 comments on commit 14a55e5

Please sign in to comment.