-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
95 autoredeploy on main change (#114)
* feat(backend): 🚀 update deployment config for ntnu server * feat(backend): 🚀 try to setup pm2 with strapi * update docs * fix(backend): 🚧 wip pm2 strapi setup * fix: 💚 fix strapi env variable * fix(frontend): 🐛 fix env variable * run action in our development branch * test push * test again * build backend before frontend * update docs * feat: ✨ Docker compose with github runner * Update autoredeploy.yml * feat: ✨ Remove env file copy * feat: ✨ Autocreate env files in autorunner * feat: ✨ Change in dockerfile syntax * feat: ✨ dockerfile node 20 * Test change action runner * Add -d for detached mode in docker files * update deployment docs * update docs * runner test * prepare for main deploy --------- Co-authored-by: EliasKnudsen <eliasskn@stud.ntnu.no>
- Loading branch information
2 people
authored and
GitHub
committed
Feb 28, 2024
1 parent
18b3878
commit 28f498e
Showing
10 changed files
with
127 additions
and
66 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
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,9 @@ | ||
| FROM node:20 | ||
| WORKDIR /usr/src/app | ||
| COPY backend /usr/src/app/backend | ||
| COPY .env /usr/src/app/backend/.env | ||
| WORKDIR /usr/src/app/backend/ | ||
| RUN npm install | ||
| RUN NODE_ENV=production npm run build | ||
| EXPOSE 1337 | ||
| CMD ["npm", "run", "start"] |
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,8 @@ | ||
| FROM node:20 | ||
| WORKDIR /usr/src/app/frontend | ||
| COPY frontend /usr/src/app/frontend | ||
| COPY .env.production /usr/src/app/frontend/.env.production | ||
| RUN npm i | ||
| RUN npm run build | ||
| EXPOSE 3000 | ||
| CMD ["npm", "run", "start"] |
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,22 +1,11 @@ | ||
| // path: ./config/env/production/database.js | ||
| const path = require("node:path"); | ||
|
|
||
| const { parse } = require("pg-connection-string"); | ||
|
|
||
| module.exports = ({ env }) => { | ||
| const { host, port, database, user, password } = parse(env("DATABASE_URL")); | ||
|
|
||
| return { | ||
| module.exports = ({ env }) => ({ | ||
| connection: { | ||
| client: "sqlite", | ||
| connection: { | ||
| client: "postgres", | ||
| connection: { | ||
| host, | ||
| port, | ||
| database, | ||
| user, | ||
| password, | ||
| ssl: { rejectUnauthorized: false }, | ||
| }, | ||
| debug: false, | ||
| filename: env("DATABASE_FILENAME", "/tmp/strapi.db") | ||
| }, | ||
| }; | ||
| }; | ||
| useNullAsDefault: true, | ||
| }, | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| const strapi = require("@strapi/strapi"); | ||
| strapi().start(); |
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,21 @@ | ||
| version: "3.8" | ||
| services: | ||
| backend-app: | ||
| volumes: | ||
| - type: bind | ||
| source: /var/data/ | ||
| target: /var/data/ | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile-backend | ||
| ports: | ||
| - "1337:1337" | ||
| environment: | ||
| - NODE_ENV=production | ||
|
|
||
| frontend-app: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile-frontend | ||
| ports: | ||
| - "3000:3000" |
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,53 @@ | ||
| See the following docs for more info about strapi deployment: | ||
| [https://docs.strapi.io/dev-docs/deployment](https://docs.strapi.io/dev-docs/deployment) | ||
|
|
||
| We use [`pm2`](https://www.npmjs.com/package/pm2) as our process manager to run our node.js frontend and backend. | ||
|
|
||
| ### Setting up ntnu halfadministrated server | ||
|
|
||
| ###### SSH | ||
|
|
||
| We have created a firewall rule to allow remote ssh connections, such that we can remote in form a github runner and autodeploy. First we create a firewall rule: | ||
|
|
||
| `/etc/local/firewall.d $ touch ipv4-magnastr-docker-website-git-autodeply.conf` | ||
|
|
||
| do `sudo nano ipv4-magnastr-docker-website-git-autodeply.conf` to enter the file and edit the content | ||
|
|
||
| paste the lines | ||
|
|
||
| ``` | ||
| -I INPUT -p tcp -m tcp --dport 22 -j ACCEPT | ||
| -I INPUT -p tcp -m tcp --dport 3000 -j ACCEPT | ||
| ``` | ||
|
|
||
| ###### PKGSYNC | ||
|
|
||
| Make sure docker compose is installed on the server. | ||
|
|
||
| Can be checked by running `docker compose version` | ||
|
|
||
| Also make sure to install `pm2` | ||
|
|
||
| ###### Github Runner | ||
|
|
||
| Setup a self hosted GitHub runner for the repository. | ||
|
|
||
| ###### Secrets and variables | ||
|
|
||
| The secrets should all be filled in and generated using `openssl rand -base64 32` | ||
|
|
||
| The GitHub repo should define the following secrets: | ||
|
|
||
| - ADMIN_JWT_SECRET | ||
| - API_TOKEN_SALT | ||
| - APP_KEYS | ||
| - JWT_SECRET | ||
| - TRANSFER_TOKEN_SALT | ||
|
|
||
| And the following variables: | ||
|
|
||
| - DATABASE_CLIENT=sqlite | ||
| - DATABASE_FILENAME=/var/data/strapi.db | ||
| - HOST=0.0.0.0 | ||
| - HOST_URL=http://backend-app:1337 | ||
| - PORT=1337 |
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,2 @@ | ||
| # Heroku Database API | ||
| HOST_URL=https://small-sat-lab-6ad3da13947b.herokuapp.com | ||
| # Database url | ||
| HOST_URL=http://backend-app:1337 |