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 27, 2023
1 parent 6da7a7a commit 62a9f3c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
8 changes: 6 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,6 @@ 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
3 changes: 3 additions & 0 deletions install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
"@typescript-eslint/parser": "^5.48.0",
"coveralls": "3.1.1",
"eslint": "^8.31.0",
"@babel/core": "7.23.2",
"babel-loader": "9.1.3",
"@babel/preset-env": "7.23.2",
"eslint-config-nodebb": "0.2.1",
"eslint-plugin-import": "2.26.0",
"grunt": "1.5.3",
Expand Down
9 changes: 9 additions & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ module.exports = {
exclude: /node_modules/,
loader: 'ignore-loader',
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']

Check failure on line 75 in webpack.common.js

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 16)

Missing trailing comma
}

Check failure on line 76 in webpack.common.js

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 16)

Missing trailing comma
}

Check failure on line 77 in webpack.common.js

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 16)

Missing trailing comma
},
],
},
};

0 comments on commit 62a9f3c

Please sign in to comment.