diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..9221331 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,85 @@ +--- +name: Deploy + +permissions: + contents: read + issues: write + pull-requests: write + +on: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: production + cancel-in-progress: true + +jobs: + deploy: + + runs-on: ubuntu-latest + environment: + name: development + url: http://${{ vars.PROD_HOST }}:3001/ + + steps: + - name: Setup SSH key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.PROD_SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H ${{ vars.PROD_HOST }} >> ~/.ssh/known_hosts + + - name: Deploy via SSH + run: | + ssh ${{ secrets.PROD_USER }}@${{ vars.PROD_HOST }} << 'EOF' + set -e + + export COMPOSE_PROGRESS=plain + export NO_COLOR=1 + + export AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" + export AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" + export AWS_DEFAULT_REGION=us-west-2 + + APP_DIR="NodeFlow" + REPO_URL="https://github.com/jlab-sensing/NodeFlow.git" + BRANCH="${{ github.ref_name }}" + + echo "::group::Cloning repository" + sudo rm -rf $APP_DIR + git clone -b "$BRANCH" "$REPO_URL" "$APP_DIR" + cd "$APP_DIR" + git fetch origin + git reset --hard ${{ steps.pr.outputs.sha }} + echo "::endgroup::" + + echo "::group::Setting up env file" + aws s3 cp s3://nodeflow-ucsc/secrets .env + sed -i "s/localhost/${{ vars.PROD_HOST }}/g" .env + echo "::endgroup::" + + echo "::group::Remove previous deployment" + docker ps -aq | xargs -r docker stop + docker ps -aq | xargs -r docker rm + docker system prune -af --volumes + docker volume prune -a -f + echo "::endgroup::" + + echo "::group::Starting services" + docker compose pull --ignore-buildable + docker compose up -d --build + sleep 5 + echo "::endgroup::" + + echo "::group::Waiting for startup" + sleep 15 + echo "::endgroup::" + + echo "::group::Startup logs" + docker compose logs --no-color + echo "::endgroup::" + EOF + diff --git a/README.md b/README.md index 5fe4156..22acef7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ Low Cost, Real-Time Automated Irrigation | Python | | Docker | -test for lint ## Getting Started @@ -21,3 +20,5 @@ For documentation on the backend, refer to [backend readme](backend/README.md) ## Builders - David Glover [dvdthr5](https://github.com/dvdthr5) + +- John Madden [jmadden173](https://github.com/jmadden173) diff --git a/backend/Dockerfile b/backend/Dockerfile index f9c1b03..24752c7 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -25,8 +25,6 @@ WORKDIR /app # copy files from source tree COPY . . -EXPOSE 8001 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"] # CI image with test-only dependencies and coverage reporting. FROM base AS test @@ -34,3 +32,9 @@ FROM base AS test RUN pip install --no-cache-dir -r requirements-dev.txt CMD ["pytest", "--cov=app", "--cov-report=term-missing", "--cov-report=xml:/app/coverage.xml"] + + +FROM base AS webserver + +EXPOSE 8001 +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"] diff --git a/docker-compose.yml b/docker-compose.yml index 555f2eb..9d62873 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,7 @@ services: build: context: ./backend dockerfile: Dockerfile + target: webserver image: nodeflow-backend env_file: - ${ENV_FILE:-.env} diff --git a/frontend/README.md b/frontend/README.md index 4cc1d56..a4330e9 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -3,3 +3,39 @@ ## Introduction The NodeFlow client is being built with [React](https://react.dev/), a component based web library + +## Testing + +We use vitest to run frontend tests. You can automatically run the frontend tests by running + +``` +npm run test:ci +``` + +## Linting + +We use eslint as the frontend linter. You can check the current status of your files by running + +``` +npm run lint +``` + +Supported lint issues can be automatically fixed by running + +``` +npx eslint --fix +``` + +## Formatting + +We use Prettier as the frontend formatter. You can check the formatting of the frontend by running + +``` +npm run format:check +``` + +and can automatically format the frontend files by running + +``` +npm run format +``` diff --git a/frontend/vite.config.js b/frontend/vite.config.js index ea0dd38..f6b899c 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -3,6 +3,10 @@ import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], + server: { + host: true, + allowedHosts: true, + }, test: { environment: 'jsdom', setupFiles: './tests/setup.js',