Skip to content

Commit

Permalink
Make deployable on GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezjo committed Oct 26, 2023
1 parent 6da7a7a commit 7a4fd76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ RUN mkdir -p /usr/src/app && \
chown -R node:node /usr/src/app
WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y jq

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

COPY --chown=node:node install/package.json /usr/src/app/package.json

USER node

RUN npm install --only=prod && \
RUN npm install && \
npm cache clean --force

COPY --chown=node:node . /usr/src/app
Expand All @@ -22,4 +24,7 @@ ENV NODE_ENV=production \

EXPOSE 4567

CMD test -n "${SETUP}" && ./nodebb setup || node ./nodebb build; node ./nodebb start
RUN chmod +x create_config.sh

CMD ./create_config.sh -n "${SETUP}" && ./nodebb setup || node ./nodebb build; node ./nodebb start

12 changes: 12 additions & 0 deletions config_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"url": "",
"secret": "c5502d62-84a5-41f1-87eb-ee33a76fb7bc",
"database": "redis",
"redis": {
"host": "",
"port": "",
"password": "",
"database": "0"
},
"port": "4567"
}
40 changes: 40 additions & 0 deletions create_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Check that environment variables have been defined
if [[ -z "${REDIS_HOST+x}" ]]; then
# var is not defined
echo "Error: REDIS_HOST is not defined!"
exit 1
fi

if [[ -z "${REDIS_PORT+x}" ]]; then
# var is not defined
echo "Error: REDIS_PORT is not defined!"
exit 1
fi

if [[ -z "${REDIS_PASSWORD+x}" ]]; then
# var is not defined
echo "Error: REDIS_PASSWORD is not defined!"
exit 1
fi

if [[ -z "${DEPLOYMENT_URL+x}" ]]; then
# var is not defined
echo "Error: DEPLOYMENT_URL is not defined!"
exit 1
fi

# Read the JSON file
json_data=$(cat "/usr/src/app/config_template.json")

# Update the JSON file with the environment variables
json_data=$(jq --arg deployment_url "$DEPLOYMENT_URL" '.url = $deployment_url' <<< "$json_data")
json_data=$(jq --arg host "$REDIS_HOST" '.redis.host = $host' <<< "$json_data")
json_data=$(jq --arg port "$REDIS_PORT" '.redis.port = $port' <<< "$json_data")
json_data=$(jq --arg password "$REDIS_PASSWORD" '.redis.password = $password' <<< "$json_data")

# Write the updated JSON file to config.json
echo "$json_data" > "/usr/src/app/config.json"

cat /usr/src/app/config.json

0 comments on commit 7a4fd76

Please sign in to comment.