From 40740a18fae028d2262d6cb989b2b7af7bf1dbc5 Mon Sep 17 00:00:00 2001 From: Jason N Date: Thu, 27 Jul 2023 15:14:09 +1000 Subject: [PATCH 1/3] Read config from environment variables before default --- server/app/config/auth.config.js | 2 +- server/app/config/db.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/app/config/auth.config.js b/server/app/config/auth.config.js index cffcb888..af1be6fe 100644 --- a/server/app/config/auth.config.js +++ b/server/app/config/auth.config.js @@ -1,3 +1,3 @@ module.exports = { - secret: "bezkoder-secret-key" + secret: process.env.AUTH_SECRET || "bezkoder-secret-key" }; \ No newline at end of file diff --git a/server/app/config/db.config.js b/server/app/config/db.config.js index 6c64b0f7..e7ebf3e4 100644 --- a/server/app/config/db.config.js +++ b/server/app/config/db.config.js @@ -1,6 +1,6 @@ module.exports = { // url: "mongodb+srv://MAPF:MONASH@mapfbenchmark.zsijqdc.mongodb.net/MAPF_test?retryWrites=true&w=majority" // url: "mongodb://127.0.0.1:27017/MAPF_V2" - url: "mongodb://127.0.0.1:27017/MAPF_V2" + url: process.env.MONGO_DB_URL || "mongodb://127.0.0.1:27017/MAPF_V2" }; From a2ab3add3fa6c84229838096e499bc0e60fac4d7 Mon Sep 17 00:00:00 2001 From: Jason N Date: Fri, 28 Jul 2023 09:09:30 +1000 Subject: [PATCH 2/3] Add Dockerfile --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0c78e53b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM node:lts-slim + +COPY . /src + +WORKDIR /src/server + +RUN npm run build + +CMD ["node", "server.js"] From d5abbaa667f8a86523f8cbb0d4d1a53ffe7e4262 Mon Sep 17 00:00:00 2001 From: Jason N Date: Fri, 28 Jul 2023 09:06:58 +1000 Subject: [PATCH 3/3] Add workflow for build and deployment --- .github/workflows/build.yml | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..e99950a8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,52 @@ +name: Build image + +on: + push: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: ${{ github.event_name != 'pull_request' && github.ref_name == 'main' && vars.DEPLOY == 'y' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + deploy: + runs-on: ubuntu-latest + needs: [build] + if: ${{ github.event_name != 'pull_request' && github.ref_name == 'main' }} + steps: + - name: Deploy to server + if: ${{ vars.DEPLOY == 'y' }} + run: | + curl -H "Authorization: Bearer ${DEPLOY_API_TOKEN}" ${DEPLOY_API_ENDPOINT} + env: + DEPLOY_API_ENDPOINT: ${{ secrets.DEPLOY_API_ENDPOINT }} + DEPLOY_API_TOKEN: ${{ secrets.DEPLOY_API_TOKEN }}