Skip to content

Commit

Permalink
updates for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
maeddes committed Jun 28, 2023
1 parent eb8c2b0 commit 2165bb1
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_BACKEND_URL=
GRAFANA_RESULT_DASHBOARD=
11 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install && npm run build
command: npm run dev


38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM --platform=$BUILDPLATFORM node:19-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
else echo "Lockfile not found." && exit 1; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM --platform=$BUILDPLATFORM nginx:1.22-alpine AS runtime
COPY --from=builder /app/dist /usr/share/nginx/html

# Adding the env-File and the Shell-Script
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY .env .

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

# Add bash
RUN apk add --no-cache bash

RUN chmod +x env.sh

# Executing the Shell-Skript
CMD ["entrypoint.sh"]
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Check if the VITE_BACKEND_URL environment variable is set
if [ -z "$VITE_BACKEND_URL" ]; then
echo "Error:
The environment variable VITE_BACKEND_URL is not set.
Please enter a valid URL, for example, '-e VITE_BACKEND_URL=http://localhost:8080' on 'docker run'."
exit 1
fi

# Run the env.sh script
source /usr/share/nginx/html/env.sh

# Start nginx
nginx -g "daemon off;"
28 changes: 28 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Recreate config file
rm -rf ./env-config.js
touch ./env-config.js

# Add assignment - window._env_ will contain all Environment-Variables, defined in .env
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
# 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/^[^=]*=//')
fi

# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}

# Append configuration property to JS file
echo " $varname: \"$value\"," >> ./env-config.js
done < .env
echo "}" >> ./env-config.js

0 comments on commit 2165bb1

Please sign in to comment.