Skip to content

Commit

Permalink
Update env variable fron VUE_ to VITE_
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes committed Dec 16, 2024
1 parent 003d948 commit 2fa241e
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 275 deletions.
24 changes: 14 additions & 10 deletions .docker/app_dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# syntax=docker/dockerfile:1
FROM node:20-bullseye AS build
SHELL ["/bin/bash", "--login", "-c"]

WORKDIR /app

Expand All @@ -8,22 +9,25 @@ EXPOSE 8081
COPY webapp/package.json webapp/yarn.lock ./

# Using a custom node_modules location to avoid mounting it outside of docker
RUN --mount=type=cache,target=/root/.cache/yarn yarn install --frozen-lockfile
RUN --mount=type=cache,target=/root/.cache/yarn yarn install --frozen-lockfile --modules-folder /node_modules

ENV NODE_ENV=production

# These get replaced by the entrypoint script for production builds.
# Set the real values in `.env` files or an external docker-compose.
ARG VUE_APP_API_URL=magic-api-url
ARG VUE_APP_LOGO_URL=magic-logo-url
ARG VUE_APP_HOMEPAGE_URL=magic-homepage-url
ARG VUE_APP_EDITABLE_INVENTORY=magic-setting
ARG VUE_APP_WEBSITE_TITLE=magic-title
ARG VUE_APP_QR_CODE_RESOLVER_URL=magic-qr-code-resolver-url
ARG VUE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT=magic-generate-id-setting
# ARG VITE_APP_API_URL=magic-api-url
ARG VITE_APP_API_URL=$VITE_APP_API_URL
ARG VITE_APP_LOGO_URL=magic-logo-url
ARG VITE_APP_HOMEPAGE_URL=magic-homepage-url
ARG VITE_APP_EDITABLE_INVENTORY=magic-setting
ARG VITE_APP_WEBSITE_TITLE=magic-title
ARG VITE_APP_QR_CODE_RESOLVER_URL=magic-qr-code-resolver-url
ARG VITE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT=magic-generate-id-setting

COPY webapp ./
RUN --mount=type=bind,target=/.git,src=./.git VUE_APP_GIT_VERSION=$(node scripts/get-version.js) yarn build
RUN --mount=type=bind,target=/.git,src=./.git VITE_APP_GIT_VERSION=$(node scripts/get-version.js)

RUN yarn build

FROM node:20-bullseye AS production

Expand All @@ -33,7 +37,7 @@ COPY ./.docker/app_entrypoint.sh /app/
COPY webapp/package.json webapp/yarn.lock ./

COPY --from=build /app/dist /app/dist
RUN --mount=type=cache,target=/root/.cache/yarn yarn install --frozen-lockfile --production
RUN --mount=type=cache,target=/root/.cache/yarn yarn install --frozen-lockfile --modules-folder /node_modules --production

CMD [ "/bin/bash", "-c", "/app/app_entrypoint.sh" ]

Expand Down
42 changes: 21 additions & 21 deletions .docker/app_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
set -e
ROOT_DIR=/app/dist

if [ -z "$VUE_APP_API_URL" ]; then
echo "VUE_APP_API_URL is unset and we are in production mode. Exiting."
if [ -z "$VITE_APP_API_URL" ]; then
echo "VITE_APP_API_URL is unset and we are in production mode. Exiting."
echo ""
echo "Found settings:"
echo ""
Expand All @@ -18,37 +18,37 @@ if [ -z "$VUE_APP_API_URL" ]; then
exit 1
fi

# If the VUE_APP_GIT_VERSION has not been overridden, set it to the default
# If the VITE_APP_GIT_VERSION has not been overridden, set it to the default
# from package.json; the real `.git` version, if available, should still
# take precedence.
if [ -z "$VUE_APP_GIT_VERSION" ]; then
VUE_APP_GIT_VERSION="0.0.0-git"
if [ -z "$VITE_APP_GIT_VERSION" ]; then
VITE_APP_GIT_VERSION="0.0.0-git"
fi

echo "Replacing env vars in Javascript files"
echo "Settings:"
echo ""
echo " APP_VERSION: ${VUE_APP_GIT_VERSION}"
echo " API_URL: ${VUE_APP_API_URL}"
echo " LOGO_URL: ${VUE_APP_LOGO_URL}"
echo " HOMEPAGE_URL: ${VUE_APP_HOMPAGE_URL}"
echo " EDITABLE_INVENTORY: ${VUE_APP_EDITABLE_INVENTORY}"
echo " WEBSITE_TITLE: ${VUE_APP_WEBSITE_TITLE}"
echo " QR_CODE_RESOLVER_URL: ${VUE_APP_QR_CODE_RESOLVER_URL}"
echo " AUTOMATICALLY_GENERATE_ID_DEFAULT: ${VUE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT}"
echo " APP_VERSION: ${VITE_APP_GIT_VERSION}"
echo " API_URL: ${VITE_APP_API_URL}"
echo " LOGO_URL: ${VITE_APP_LOGO_URL}"
echo " HOMEPAGE_URL: ${VITE_APP_HOMPAGE_URL}"
echo " EDITABLE_INVENTORY: ${VITE_APP_EDITABLE_INVENTORY}"
echo " WEBSITE_TITLE: ${VITE_APP_WEBSITE_TITLE}"
echo " QR_CODE_RESOLVER_URL: ${VITE_APP_QR_CODE_RESOLVER_URL}"
echo " AUTOMATICALLY_GENERATE_ID_DEFAULT: ${VITE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT}"
echo ""
echo "Patching..."

for file in $ROOT_DIR/js/app.*.js* $ROOT_DIR/*html; do
echo "$file"
sed -i "s|0.0.0-git|${VUE_APP_GIT_VERSION}|g" $file
sed -i "s|magic-api-url|${VUE_APP_API_URL}|g" $file
sed -i "s|magic-logo-url|${VUE_APP_LOGO_URL}|g" $file
sed -i "s|magic-homepage-url|${VUE_APP_HOMEPAGE_URL}|g" $file
sed -i "s|magic-setting|${VUE_APP_EDITABLE_INVENTORY}|g" $file
sed -i "s|magic-title|${VUE_APP_WEBSITE_TITLE}|g" $file
sed -i "s|magic-qr-code-resolver-url|${VUE_APP_QR_CODE_RESOLVER_URL}|g" $file
sed -i "s|magic-generate-id-setting|${VUE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT}|g" $file
sed -i "s|0.0.0-git|${VITE_APP_GIT_VERSION}|g" $file
sed -i "s|magic-api-url|${VITE_APP_API_URL}|g" $file
sed -i "s|magic-logo-url|${VITE_APP_LOGO_URL}|g" $file
sed -i "s|magic-homepage-url|${VITE_APP_HOMEPAGE_URL}|g" $file
sed -i "s|magic-setting|${VITE_APP_EDITABLE_INVENTORY}|g" $file
sed -i "s|magic-title|${VITE_APP_WEBSITE_TITLE}|g" $file
sed -i "s|magic-qr-code-resolver-url|${VITE_APP_QR_CODE_RESOLVER_URL}|g" $file
sed -i "s|magic-generate-id-setting|${VITE_APP_AUTOMATICALLY_GENERATE_ID_DEFAULT}|g" $file
done

echo "Done!"
Expand Down
Loading

0 comments on commit 2fa241e

Please sign in to comment.