From d6321fa220b14fd44d589e2b9170213cd85c3f73 Mon Sep 17 00:00:00 2001 From: pawan-59 Date: Tue, 31 Dec 2024 18:42:48 +0530 Subject: [PATCH 1/6] Updated docker file to remove extra layers --- Dockerfile | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e2df69eab..1cb1818109 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,36 +3,33 @@ 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 . . -RUN echo `git rev-parse --short HEAD` > health.html - -RUN echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env - -RUN yarn build +RUN echo `git rev-parse --short HEAD` > health.html && \ + echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env && \ + yarn build FROM nginx:stable 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;\""] From b73fe3659e00c68821d6ff659591f1ae5a7de5df Mon Sep 17 00:00:00 2001 From: Neha Sharma Date: Thu, 16 Jan 2025 11:33:03 +0530 Subject: [PATCH 2/6] change the base image --- Dockerfile | 6 ++++-- env.sh | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1cb1818109..af96bb5d6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,9 @@ RUN echo `git rev-parse --short HEAD` > health.html && \ echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env && \ yarn build -FROM nginx:stable +FROM nginx:stable-alpine + +RUN apk add --no-cache shadow RUN useradd -ms /bin/bash devtron @@ -32,4 +34,4 @@ RUN chmod +x env.sh USER devtron -CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] +CMD ["/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] diff --git a/env.sh b/env.sh index 8120287b0a..0125061573 100755 --- a/env.sh +++ b/env.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Copyright (c) 2024. Devtron Inc. @@ -17,32 +17,35 @@ # # Recreate config file -rm -rf ./env-config.js +rm -f ./env-config.js touch ./env-config.js -# Add assignment +# Add assignment echo "window._env_ = {" >> ./env-config.js # Read each line in .env file # Each line represents key=value pairs -while read -r line || [[ -n "$line" ]]; -do +while IFS= read -r line || [ -n "$line" ]; do # Split env variables by character `=` - if printf '%s\n' "$line" | grep -q -e '='; then - varname=$(printf '%s\n' "$line" | sed -e 's/=.*//') - varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//') + if echo "$line" | grep -q '='; then + varname=$(echo "$line" | sed 's/=.*//') + varvalue=$(echo "$line" | sed 's/^[^=]*=//') fi # Read value of current variable if exists as Environment variable - value=$(printf '%s\n' "${!varname}") + value=$(eval echo "\$$varname") + # Otherwise use value from .env file - [[ -z $value ]] && value=${varvalue} - + if [ -z "$value" ]; then + value="$varvalue" + fi + # Append configuration property to JS file - if [[ "$value" == "true" ]] || [[ "$value" == "false" ]]; then + if [ "$value" = "true" ] || [ "$value" = "false" ]; then echo " $varname: $value," >> ./env-config.js else echo " $varname: \"$value\"," >> ./env-config.js fi done < .env + echo "}" >> ./env-config.js From e5a6d71a96e2159af4050357bf7653a3b4dd488c Mon Sep 17 00:00:00 2001 From: Neha Sharma Date: Thu, 16 Jan 2025 12:34:14 +0530 Subject: [PATCH 3/6] changes --- Dockerfile | 2 +- env.sh | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index af96bb5d6b..2057b97c5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,4 +34,4 @@ RUN chmod +x env.sh USER devtron -CMD ["/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] +CMD ["/usr/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] diff --git a/env.sh b/env.sh index 0125061573..96d21251bc 100755 --- a/env.sh +++ b/env.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/sh # # Copyright (c) 2024. Devtron Inc. @@ -17,35 +17,32 @@ # # Recreate config file -rm -f ./env-config.js +rm -rf ./env-config.js touch ./env-config.js -# Add assignment +# Add assignment echo "window._env_ = {" >> ./env-config.js # Read each line in .env file # Each line represents key=value pairs -while IFS= read -r line || [ -n "$line" ]; do +while read -r line || [[ -n "$line" ]]; +do # Split env variables by character `=` - if echo "$line" | grep -q '='; then - varname=$(echo "$line" | sed 's/=.*//') - varvalue=$(echo "$line" | sed 's/^[^=]*=//') + if printf '%s\n' "$line" | grep -q -e '='; then + varname=$(printf '%s\n' "$line" | sed -e 's/=.*//') + varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//') fi # Read value of current variable if exists as Environment variable - value=$(eval echo "\$$varname") - + value=$(printf '%s\n' "${!varname}") # Otherwise use value from .env file - if [ -z "$value" ]; then - value="$varvalue" - fi - + [[ -z $value ]] && value=${varvalue} + # Append configuration property to JS file - if [ "$value" = "true" ] || [ "$value" = "false" ]; then + if [[ "$value" == "true" ]] || [[ "$value" == "false" ]]; then echo " $varname: $value," >> ./env-config.js else echo " $varname: \"$value\"," >> ./env-config.js fi done < .env - echo "}" >> ./env-config.js From fba6ef4e821d964c4a6a0d166d83210e212701af Mon Sep 17 00:00:00 2001 From: Neha Sharma Date: Thu, 16 Jan 2025 13:25:15 +0530 Subject: [PATCH 4/6] add sleep --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2057b97c5f..640b7164db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ COPY package.json yarn.lock . RUN yarn install --network-timeout 600000 -COPY . . +COPY . .apk add --no-cache git + RUN echo `git rev-parse --short HEAD` > health.html && \ echo "SENTRY_RELEASE_VERSION=dashboard@$(git rev-parse --short HEAD)" >> .env && \ @@ -34,4 +35,5 @@ RUN chmod +x env.sh USER devtron -CMD ["/usr/bin/sh", "-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;\""] From fddd9066985414bbff936829e50b537d2bd51717 Mon Sep 17 00:00:00 2001 From: Neha Sharma Date: Thu, 16 Jan 2025 14:10:08 +0530 Subject: [PATCH 5/6] . --- env.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/env.sh b/env.sh index 96d21251bc..b4904565e4 100755 --- a/env.sh +++ b/env.sh @@ -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 From 92df9c62c74b82a2f34d7b422389a5ae271ed49c Mon Sep 17 00:00:00 2001 From: Neha Sharma Date: Thu, 16 Jan 2025 14:12:03 +0530 Subject: [PATCH 6/6] . --- env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env.sh b/env.sh index b4904565e4..4b786944e7 100755 --- a/env.sh +++ b/env.sh @@ -1,4 +1,4 @@ -#!/usr/bin/sh +#!/bin/sh # # Copyright (c) 2024. Devtron Inc.