Skip to content

Commit

Permalink
chore: add production environment (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalholt committed Aug 14, 2023
1 parent 90486d9 commit 6228875
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev-vote-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: "ntnui-vote-backend-dev"
slot-name: "Production"
app-name: "vote-backend/dev"
slot-name: "development"
publish-profile: ${{ secrets.AZURE_BACKEND_DEV_PUBLISH_PROFILE }}
package: "./backend"
64 changes: 64 additions & 0 deletions .github/workflows/deploy-prod-vote-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy prod backend

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: npm install, build, and test
run: |
cd backend
npm install
npm run build
- name: Zip artifact for deployment job
run: zip -r -q release.zip ./*

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: node-app
path: release.zip

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: "Development"
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: node-app

- name: Unzip artifact for deployment job
run: |
unzip -q release.zip
rm release.zip
- name: "Deploy to Azure Web App"
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: "vote-backend"
slot-name: "production"
publish-profile: ${{ secrets.AZURE_BACKEND_PROD_PUBLISH_PROFILE }}
package: "./backend"
52 changes: 52 additions & 0 deletions .github/workflows/deploy-prod-vote-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and deploy dev frontend

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
paths-ignore:
- "**"
- "!frontend/**"
workflow_dispatch:

jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_FRONTEND_PROD_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/frontend" # App source code path
api_location: "" # Api source code path - optional
output_location: "/dist" # Built app content directory - optional
###### End of Repository/Build Configurations ######
env:
VITE_BACKEND_URL: https://api.vote.ntnui.no
VITE_SOCKET_URL: wss://api.vote.ntnui.no/lobby

close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_FRONTEND_PROD_TOKEN }}
action: "close"
9 changes: 8 additions & 1 deletion backend/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ const mongoConnect = async () => {
console.error("ERROR: ", e);
}

database = mongoose.connection;
if (process.env.NODE_ENV === "development") {
database = mongoose.connection.useDb("development");
} else if (process.env.NODE_ENV === "production") {
database = mongoose.connection.useDb("production");
} else {
database = mongoose.connection;
}

database.once("open", async () => {
console.log("Connected to MongoDB 🌱");
});
Expand Down

0 comments on commit 6228875

Please sign in to comment.