Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: Optimize Dockerfile by Removing Extra Layers #2331

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ FROM node:20-alpine AS builder
RUN apk add --no-cache git

WORKDIR /app
COPY package.json .
COPY yarn.lock .
COPY package.json yarn.lock .

RUN yarn install --network-timeout 600000

COPY src/ src
COPY nginx.conf .
COPY tsconfig.json .
COPY vite.config.mts .
COPY . .
COPY . .apk add --no-cache git

RUN echo `git rev-parse --short HEAD` > health.html

RUN echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env
RUN echo `git rev-parse --short HEAD` > health.html && \
echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env && \
yarn build

RUN yarn build
FROM nginx:stable-alpine

FROM nginx:stable
RUN apk add --no-cache shadow

RUN useradd -ms /bin/bash devtron

COPY --from=builder /app/dist/ /usr/share/nginx/html

COPY ./nginx.conf /etc/nginx/nginx.conf

COPY ./nginx-default.conf /etc/nginx/conf.d/default.conf

WORKDIR /usr/share/nginx/html
COPY --from=builder /app/./env.sh .
COPY --from=builder /app/.env .
COPY --from=builder /app/health.html .

RUN chown -R devtron:devtron /usr/share/nginx/html
COPY --chown=devtron:devtron --from=builder /app/./env.sh /app/health.html /app/.env .

# Make our shell script executable
RUN chmod +x env.sh

USER devtron
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]

CMD ["/usr/bin/sh", "-c", "sleep 3567898"]
# CMD ["/usr/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
6 changes: 5 additions & 1 deletion env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

#
# Copyright (c) 2024. Devtron Inc.
Expand All @@ -17,9 +17,13 @@
#

# Recreate config file


rm -rf ./env-config.js
touch ./env-config.js

chmod +x env-config.js

# Add assignment
echo "window._env_ = {" >> ./env-config.js

Expand Down
Loading