Created
October 31, 2020 23:55
-
-
Save fmdlc/7f8d953faa206100bba0e6ce466c67cd to your computer and use it in GitHub Desktop.
Dockerfile build multistage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### STAGE 1: clone ### | |
FROM node:12.16.3-alpine3.9 AS clone | |
LABEL mantainer="Facu de la Cruz <[email protected]>" | |
LABEL type="builder" | |
WORKDIR /usr/src/frontend | |
# We need to install those packages to use npm | |
# A few repositories are cloned by using Git over SSH | |
RUN apk add --update --no-cache \ | |
build-base=0.5-r1 \ | |
git=2.20.4-r0 \ | |
openssh-client=7.9_p1-r6 | |
# configure git credentials | |
RUN mkdir /root/.ssh/ | |
COPY ./config/id_rsa_overwatch /root/.ssh/id_rsa | |
RUN chmod 400 /root/.ssh/id_rsa && \ | |
touch /root/.ssh/known_hosts && \ | |
ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts && \ | |
git config --global user.email "[email protected]" && \ | |
git clone --branch walmart [email protected]:repository/repo.git | |
## STAGE 2: build | |
FROM node:12.16.3-alpine3.9 AS build | |
LABEL mantainer="Facu de la Cruz <[email protected]>" | |
LABEL type="builder" | |
LABEL app="frontend-node8" | |
RUN apk add --update --no-cache \ | |
build-base=0.5-r1 \ | |
git=2.20.4-r0 \ | |
openssh-client=7.9_p1-r6 | |
WORKDIR /usr/src/frontend | |
COPY --from=clone /usr/src/frontend/ /usr/src/frontend | |
# Hide warning coming from NPM | |
ENV npm_config_loglevel=error | |
# Increase memory space size for ng | |
ENV NODE_OPTIONS="--max_old_space_size=4096" | |
RUN awk -v COMMIT=$(git log --format="%h" -n 1) \ | |
-v BRANCH=$(git rev-parse --abbrev-ref HEAD) \ | |
-v DATE=$(date +%s) \ | |
-F'=' '/currentVersion/ { gsub("(\;| )",""); \ | |
print "{\n\t\"version\": \""$2"-"COMMIT"\",\n\t\"built-branch\": \""BRANCH"\",\n\t\"built-date\": \""DATE"\"\n}"}' \ | |
src/app/shared/footer/footer.component.ts | tr -d \' > \ | |
/usr/src/frontend/version.json | |
RUN npm install --loglevel verbose && \ | |
npm install -g @angular/[email protected] && \ | |
ng build --prod | |
### STAGE 3: Run ### | |
FROM nginx:1.17.9-alpine | |
LABEL mantainer="Facu de la Cruz <[email protected]>" | |
LABEL type="app" | |
LABEL app="frontend-node8" | |
ENV NGINX_PORT=80 | |
# copy nginx configuration | |
COPY ./config/nginx.conf /etc/nginx/nginx.conf | |
COPY ./config/default.conf /etc/nginx/conf.d/default.conf | |
# copy frontend and landing page | |
COPY --from=build /usr/src/frontend/dist/ /usr/share/nginx/html | |
COPY --from=build /usr/src/frontend/version.json /usr/share/nginx/html/version.json | |
STOPSIGNAL SIGINT | |
EXPOSE 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment