Skip to content

Commit

Permalink
add cleanup tasks and chainguard/node image
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidChevallier committed Jul 14, 2024
1 parent 1a3c6fa commit 2586e83
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
ARG ALPINE_V=3.18
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_V} as build-base
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_V} AS build-base

ARG TAR_V=1.34
RUN apk update && \
apk add --no-cache curl xz busybox gcc g++ make musl-dev nodejs npm && \
curl -fsSL http://ftp.gnu.org/gnu/tar/tar-${TAR_V}.tar.gz -o tar-${TAR_V}.tar.gz && \
tar -xzf tar-${TAR_V}.tar.gz && \
cd tar-${TAR_V} && \
export FORCE_UNSAFE_CONFIGURE=1 && \
./configure && \
make && \
make install && \
cd .. && \
rm -rf tar-${TAR_V} tar-${TAR_V}.tar.gz

FROM build-base as build
apk add --no-cache curl xz busybox gcc g++ make musl-dev nodejs npm

FROM build-base AS build
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY . .
RUN npm install
RUN npm run build

FROM --platform=$TARGETPLATFORM cgr.dev/chainguard/wolfi-base as wolfi-node
ENV USER="rocketalert"
FROM build AS cleanup
RUN find /opt/app -name "*.md" -type f -exec rm -f {} + && \
find /opt/app -name ".DS_Store" -type f -exec rm -f {} + && \
find /opt/app -name ".vscode" -type d -exec rm -rf {} + && \
find /opt/app -name ".gitlab" -type d -exec rm -rf {} + && \
find /opt/app -name ".dockerignore" -type f -exec rm -f {} + && \
find /opt/app -name "docker-compose.yml" -type f -exec rm -f {} + && \
find /opt/app -name "Dockerfile" -type f -exec rm -f {} +

RUN mkdir -p /opt/app && \
adduser -D ${USER} && \
chown -R ${USER}:${USER} /opt/app
FROM --platform=$TARGETPLATFORM cgr.dev/chainguard/node:latest AS wolfi-node
ENV USER="node"

#USER ${USER}
WORKDIR /app
COPY --from=cleanup --chown=${USER}:${USER} /opt/app /app

COPY --from=build --chown=${USER}:${USER} /usr/local /usr/local
COPY --from=build --chown=${USER}:${USER} /usr/lib /usr/lib
COPY --from=build --chown=${USER}:${USER} /usr/bin/node /usr/bin/node
COPY --from=build --chown=${USER}:${USER} /usr/bin/npm /usr/bin/npm
RUN npm install

WORKDIR /opt/app
COPY --from=build --chown=${USER}:${USER} /opt/app/build ./build
COPY --from=build --chown=${USER}:${USER} /opt/app/node_modules ./node_modules
COPY --from=build --chown=${USER}:${USER} /opt/app/package.json ./
COPY --from=build --chown=${USER}:${USER} /opt/app/package-lock.json ./

# FIXME: /bin/ash: node: not found - https://edu.chainguard.dev/chainguard/chainguard-images/getting-started/node/
CMD ["/usr/bin/node", "npm", "start"]
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/ || exit 1

CMD ["node", "src/App.js"]
EXPOSE 3000

0 comments on commit 2586e83

Please sign in to comment.