-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multiplatform docker image build (#201)
- Loading branch information
Showing
8 changed files
with
126 additions
and
168 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,102 @@ | ||
FROM ubuntu:22.04 | ||
# use native build platform for build js files only once | ||
FROM --platform=${BUILDPLATFORM} ubuntu:22.04 AS native-build-stage | ||
|
||
ARG NODE_MAJOR=20 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
ENV NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/cert.pem | ||
|
||
RUN apt-get update && apt-get -y upgrade | ||
|
||
# node | ||
RUN apt-get -y install ca-certificates curl gnupg | ||
RUN mkdir -p /etc/apt/keyrings | ||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | ||
|
||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | ||
|
||
RUN apt-get update && apt-get -y install nodejs g++ make | ||
|
||
RUN useradd -m -u 1000 app && mkdir /opt/app && chown app:app /opt/app | ||
|
||
WORKDIR /opt/app | ||
|
||
COPY package.json package-lock.json .npmrc /opt/app/ | ||
RUN npm ci | ||
|
||
COPY ./dist /opt/app/dist | ||
COPY ./src /opt/app/src | ||
COPY ./typings /opt/app/typings | ||
COPY tsconfig.json /opt/app/ | ||
|
||
RUN npm run build && chown app /opt/app/dist/run | ||
|
||
# runtime base image for both platform | ||
FROM ubuntu:22.04 AS base-stage | ||
|
||
ARG NODE_MAJOR=20 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt-get update && apt-get -y upgrade | ||
|
||
# node | ||
RUN apt-get -y install ca-certificates curl gnupg | ||
RUN mkdir -p /etc/apt/keyrings | ||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | ||
|
||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | ||
|
||
RUN apt-get update | ||
RUN apt-get -y install nodejs | ||
|
||
# install postgresql-client | ||
RUN apt-get -y install postgresql-client | ||
|
||
# remove unnecessary packages | ||
RUN apt-get -y purge curl gnupg gnupg2 && \ | ||
apt-get -y autoremove && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# timezone setting | ||
ENV TZ="Etc/UTC" | ||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime | ||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | ||
|
||
# add node.js repository | ||
RUN apt-get update && \ | ||
apt-get install -y ca-certificates curl gnupg && \ | ||
mkdir -p /etc/apt/keyrings && \ | ||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ | ||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | ||
# user app | ||
RUN useradd -m -u 1000 app && mkdir /opt/app && chown app:app /opt/app | ||
|
||
# add postgresql repository | ||
RUN install -d /usr/share/postgresql-common/pgdg && \ | ||
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc && \ | ||
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt jammy-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list | ||
# install package dependencies for production | ||
FROM base-stage AS install-stage | ||
|
||
# install system dependencies | ||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && \ | ||
apt-get -y install nginx supervisor nodejs postgresql-client-13 build-essential | ||
RUN apt-get update && apt-get -y install g++ make | ||
|
||
# cleanup tmp and defaults | ||
RUN rm -rf /etc/nginx/sites-enabled/default /var/lib/apt/lists/* | ||
WORKDIR /opt/app | ||
|
||
ARG app_version | ||
ARG CERT | ||
ARG USER=app | ||
COPY package.json package-lock.json .npmrc /opt/app/ | ||
|
||
ENV APP_VERSION=$app_version | ||
ENV NODE_ENV=production | ||
RUN npm ci && npm prune --production | ||
|
||
RUN mkdir -p /opt/app | ||
# production running stage | ||
FROM base-stage AS runtime-stage | ||
|
||
RUN useradd -ms /bin/bash --uid 1000 ${USER} | ||
ARG USER=app | ||
ARG app_version | ||
ENV APP_VERSION=$app_version | ||
|
||
WORKDIR /opt/app | ||
|
||
|
||
COPY deploy/nginx /etc/nginx | ||
COPY deploy/supervisor /etc/supervisor/conf.d | ||
COPY package.json package-lock.json /opt/app/ | ||
COPY . . | ||
|
||
# prepare rootless permissions for supervisor and nginx | ||
RUN chown -R ${USER} /var/log/supervisor/ && \ | ||
mkdir /var/run/supervisor && \ | ||
chown -R ${USER} /var/run/supervisor && \ | ||
mkdir -p /var/cache/nginx && chown -R ${USER} /var/cache/nginx && \ | ||
mkdir -p /var/log/nginx && chown -R ${USER} /var/log/nginx && \ | ||
mkdir -p /var/lib/nginx && chown -R ${USER} /var/lib/nginx && \ | ||
touch /run/nginx.pid && chown -R ${USER} /run/nginx.pid | ||
|
||
# build app | ||
RUN npm ci -q --no-progress --include=dev --also=dev | ||
RUN npm run build | ||
RUN npm prune --production | ||
RUN rm -rf /tmp/* | ||
|
||
RUN chown -R ${USER} /opt/app/dist/run | ||
COPY --from=install-stage /opt/app/node_modules /opt/app/node_modules | ||
COPY --from=native-build-stage /opt/app/dist /opt/app/dist | ||
|
||
# adding certificate | ||
RUN echo $CERT > /usr/local/share/ca-certificates/cert.pem | ||
ENV NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/cert.pem | ||
RUN update-ca-certificates | ||
RUN chown -R ${USER} /opt/app/dist/run | ||
|
||
USER app | ||
|
||
ENTRYPOINT [ "/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf" ] | ||
ENV NODE_ENV=production | ||
ENV APP_PORT=8083 | ||
|
||
ENTRYPOINT ["./scripts/preflight.sh"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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