Skip to content

simple comment change to reset svante3 database #279

simple comment change to reset svante3 database

simple comment change to reset svante3 database #279

Workflow file for this run

name: Build And Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
build-backend:
runs-on: ubuntu-20.04
env:
SQLX_VERSION: ^0.6.2
SQLX_FEATURES: rustls postgres
APP_URL: 127.0.0.1
APP_PORT: 8080
EDITOR_PORT: 4040
DATABASE_USER: username
DATABASE_PASSWORD: password
DATABASE_NAME: database
DATABASE_PORT: 5432
DATABASE_HOST: localhost
DATABASE_URL: postgres://username:password@localhost/database
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
POSTGRES_DB: database
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache dependencies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
backend/target/
key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }}
- name: ⚡ Cache sqlx-cli
uses: actions/cache@v2
id: cache-sqlx
with:
path: |
~/.cargo/bin/sqlx
~/.cargo/bin/cargo-sqlx
key: ${{ runner.os }}-cargo-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }}
- name: Install sqlx-cli
if: steps.cache-sqlx.outputs.cache-hit == false
run: cargo install sqlx-cli --force --version ${{ env.SQLX_VERSION }} --no-default-features --features "${{ env.SQLX_FEATURES }}"
- name: Migrate database
run: SKIP_DOCKER=true ./init_db.sh
working-directory: backend
- name: 🔨 Build
run: cargo build --release --verbose
working-directory: backend
- name: 🧪 Test
run: cargo test
working-directory: backend
- name: tar files to keep permissions
run: |
mv target/release/climate_risk_map ./
tar -cvf backend.tar climate_risk_map migrations
working-directory: backend
- uses: actions/upload-artifact@v2
with:
name: backend
path: backend/backend.tar
build-frontend:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: "20"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
working-directory: frontend
- name: ⚡ Cache yarn dependencies
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', 'frontend/.yarnrc.yml') }}
restore-keys: |
yarn-cache-folder-
- name: 🔨 Build
run: |
yarn install --immutable
yarn lint
yarn build
working-directory: frontend
- name: 🧪 Test
run: yarn test
working-directory: frontend
- uses: actions/upload-artifact@v2
with:
name: frontend
path: frontend/build
deploy-development:
if: github.event_name == 'pull_request'
environment:
name: development
url: https://svante3.mit.edu
needs: [build-backend, build-frontend]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v2
with:
path: ${{ github.event.pull_request.head.sha }}
- name: extract backend
run: |
tar -xvf backend.tar
rm backend.tar
working-directory: ${{ github.event.pull_request.head.sha }}/backend
- name: deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ${{ github.event.pull_request.head.sha }}
target: ~/builds/
- name: run on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: >
podman pod start crm_pod &&
podman stop crm_backend &&
ln -snf ~/builds/${{ github.event.pull_request.head.sha }} ~/climate-risk-map &&
podman run --rm -v ~/climate-risk-map/backend:/opt/climate-risk-map/backend:Z --tz=America/New_York --env-file=$HOME/.env --pod=crm_pod sqlx database reset -y &&
podman start crm_backend
deploy-production:
if: github.event_name == 'push'
environment:
name: production
url: https://est.mit.edu
needs: [build-backend, build-frontend]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v2
with:
path: ${{ github.sha }}
- name: extract backend
run: |
tar -xvf backend.tar
rm backend.tar
working-directory: ${{ github.sha }}/backend
- name: deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ${{ github.sha }}
target: ~/builds/
- name: run on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: >
podman stop crm_backend &&
ln -snf ~/builds/${{ github.sha }} ~/climate-risk-map &&
podman run --rm -v ~/climate-risk-map/backend:/opt/climate-risk-map/backend:Z --tz=America/New_York --env-file=$HOME/.env --pod=crm_pod sqlx migrate run &&
podman start crm_backend