forked from venetoarpa/Arpav-PPCV
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ricardogsilva/specify-backend-urls-via-env
Specify backend urls via env
- Loading branch information
Showing
26 changed files
with
124 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
build/ | ||
build/ | ||
public/injectedEnv.js |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ node_modules | |
stats.json | ||
.pnp | ||
.pnp.js | ||
public/injectedEnv.js | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
FROM node:16-alpine AS builder | ||
ENV NODE_ENV production | ||
ENV \ | ||
NODE_ENV=production \ | ||
GENERATE_SOURCEMAP=false | ||
# Add a work directory | ||
WORKDIR /app | ||
# Cache and Install dependencies | ||
COPY package.json . | ||
COPY yarn.lock . | ||
RUN yarn install --production | ||
RUN yarn install --production --frozen-lockfile | ||
# Copy app files | ||
COPY . . | ||
# Build the app | ||
RUN yarn build | ||
|
||
# Bundle static assets with nginx | ||
FROM nginx:1.21.0-alpine as production | ||
ENV NODE_ENV production | ||
# Copy built assets from builder | ||
COPY --from=builder /app/build /usr/share/nginx/html | ||
# Add your nginx.conf | ||
FROM nginx:1.21.0-alpine AS production | ||
ENV \ | ||
NODE_ENV=production \ | ||
ARPAV_BACKEND_API_BASE_URL=http://localhost:8877 \ | ||
ARPAV_TOLGEE_BASE_URL=http://localhost:8899 | ||
WORKDIR /usr/share/nginx/html | ||
COPY --from=builder /app/build . | ||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
# Expose port | ||
COPY docker-entrypoint.sh . | ||
COPY injectEnv.sh . | ||
EXPOSE 80 | ||
# Start nginx | ||
CMD ["nginx", "-g", "daemon off;"] | ||
ENTRYPOINT [ "sh", "docker-entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,25 +13,35 @@ This work is licensed under a <a rel="license" href="https://creativecommons.org | |
Commissioned by & Data credits to <br/> | ||
<a href="https://www.arpa.veneto.it/"><img src="https://github.com/inkode-it/Arpav-PPCV/raw/main/public/img/logo_arpav.png" alt="ARPAV" style="background-color:white;padding:4px"></a> | ||
|
||
Designed and developed in Italy by <br/> | ||
<a rel="author" href="mailto:[email protected]"><img src="https://avatars.githubusercontent.com/u/64135645" alt="INKODE soc coop"></a> | ||
|
||
Current version was designed and developed in Italy by <br/> | ||
<a rel="author" href="mailto:[email protected]"><img src="https://avatars.githubusercontent.com/u/1163234?s=200&v=4" alt="Geobeyond"></a> | ||
|
||
A previous version had originally been developed by [inkode](http://inkode.it) | ||
|
||
|
||
## Install & development | ||
|
||
This project uses the [Yarn Package Manager](https://yarnpkg.com) . | ||
This project uses node version 16. It uses the [Yarn Package Manager](https://yarnpkg.com) and is known to work | ||
with yarn v1.22.22. Start by ensuring you meet these conditions (install node and yarn). | ||
|
||
Install dependencies | ||
Now for installing this project: | ||
|
||
```shell | ||
yarn install | ||
yarn install --frozen-lockfile | ||
``` | ||
|
||
Before launching the application, copy the contents of `.env.example` file to `.env` and edit Environment variables. | ||
Before launching the application, ensure you have the following environment variables: | ||
|
||
- `ARPAV_BACKEND_API_BASE_URL` - base URL of the backend. Example: `http://localhost:8877` | ||
- `ARPAV_TOLGEE_BASE_URL` - base URL of the tolgee service. Example: `http://localhost:8899` | ||
|
||
Create the `public/injectedEnv.js` file by running: | ||
|
||
```shell | ||
yarn inject-env public | ||
``` | ||
|
||
Launch application in development mode | ||
Then launch application in development mode: | ||
|
||
```shell | ||
yarn start | ||
|
@@ -64,10 +74,21 @@ http://localhost:3000 | |
- `src/app/pages/MapPage/slice`: Redux and Redux-Saga management; | ||
- `src/utils`: Utility functions. | ||
|
||
## Docker build command for production | ||
# Running in production | ||
|
||
Build the docker image: | ||
|
||
```shell | ||
docker build -t ppcv_frontend -f production.Dockerfile . | ||
docker build -t ppcv_frontend -f Dockerfile . | ||
``` | ||
|
||
Run the built container with: | ||
|
||
```shell | ||
docker run \ | ||
-e ARPAV_BACKEND_API_BASE_URL=http://localhost:8877 \ | ||
-e ARPAV_TOLGEE_BASE_URL=http://localhost:8899 \ | ||
-p 3000:80 \ | ||
ppcv_frontend | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
cd /usr/share/nginx/html | ||
sh injectEnv.sh | ||
|
||
[ -z "$@" ] && nginx -g 'daemon off;' || "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
output_dir="${1:-.}" | ||
|
||
output_file="${output_dir}/injectedEnv.js" | ||
|
||
echo "(Re)generating '${output_file}' by writing environment variables starting with 'ARPAV_' into it..." | ||
|
||
# Start writing the JavaScript file | ||
cat > "$output_file" << EOL | ||
// This file is autogenerated | ||
window.injectedEnv = { | ||
EOL | ||
|
||
# Process only environment variables starting with ARPAV_ | ||
env | grep "^ARPAV_" | while IFS='=' read -r key value; do | ||
# Clean the value: escape quotes and backslashes | ||
cleaned_value=$(echo "$value" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') | ||
|
||
# Write the key-value pair as a JavaScript property | ||
echo " \"$key\": \"$cleaned_value\"," >> "$output_file" | ||
done | ||
|
||
cat >> "$output_file" << EOL | ||
}; | ||
EOL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.