From 22b34771e6405a5e931c9ea80b85f2c14dbc1eb5 Mon Sep 17 00:00:00 2001 From: Aadesh-Baral Date: Mon, 20 Mar 2023 10:06:06 +0545 Subject: [PATCH] Add job to deploy frontend to droplet instead of netlify --- .circleci/config.yml | 26 ++++++++++++++++++++++---- backend/models/sql/features.py | 2 ++ frontend/package.json | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0c1f6a9..2901ab3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 jobs: - build-and-deploy: + backend-deploy: # Use the Docker executor to run Docker commands docker: - image: docker:20.10.12 @@ -19,12 +19,26 @@ jobs: && docker build -t localizer-backend:latest ." # SSH into the DigitalOcean droplet and deploy the app using Docker Compose - run: - name: Deploy app + name: Deploy backend command: | ssh -oStrictHostKeyChecking=no -v ${SSH_USER}@${SERVER_IP} "cd OSMLocalizer \ && docker-compose down \ && docker-compose up -d" - + frontend-deploy: + docker: + - image: cimg/node:18.15.0 + steps: + - checkout + - run: + name: Create build + command: | + cd frontend \ + && npm install \ + && npm run build + - run: + name: Deploy frontend + command: | + scp -oStrictHostKeyChecking=no -r frontend/build ${SSH_USER}@${SERVER_IP}:/home/${SSH_USER}/OSMLocalizer/frontend # Run jobs from above in configurable sequences called workflows workflows: @@ -32,7 +46,11 @@ workflows: # Workflow name build-deploy: jobs: - - build-and-deploy: + - backend-deploy: + filters: + branches: + only: master + - frontend-deploy: filters: branches: only: master diff --git a/backend/models/sql/features.py b/backend/models/sql/features.py index d7e1da8..d22a74c 100644 --- a/backend/models/sql/features.py +++ b/backend/models/sql/features.py @@ -135,4 +135,6 @@ def get_nearby(feature_id, challenge_id): ).fetchall() if nearby: feature = Feature.get_by_id(nearby[0][0], challenge_id) + else: + raise NotFound("NO_FEATURES_TO_LOCALIZE") return feature diff --git a/frontend/package.json b/frontend/package.json index 1032556..201e8b7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,7 +33,7 @@ "scripts": { "preparation": "bash -c \"if (test -a ../localizer.env); then grep -hs ^ ../localizer.env .env.expand > .env; else cp .env.expand .env; fi\"", "start": "npm run preparation && react-scripts start", - "build": "react-scripts build", + "build": "npm run preparation && react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", "lint": "eslint --ext .js,.jsx,.ts,.tsx --fix src/",