diff --git a/.env.sample b/.env.sample index 300e463bd..7c09ba660 100644 --- a/.env.sample +++ b/.env.sample @@ -1,12 +1,12 @@ PYTHON_ENV=dev -DB_TYPE=mysql +DB_TYPE=postgresql DB_NAME=dbname DB_USER=user DB_PASSWORD=password DB_HOST=127.0.0.1 -DB_PORT=3306 -MYSQL_DRIVER=pymysql -DB_URL="mysql+pymysql://user:password@127.0.0.1:3306/dbname" +DB_PORT=5432 +MYSQL_DRIVER=pymysql +DB_URL="postgresql://user:password@127.0.0.1:5432/dbname" SECRET_KEY = "" ALGORITHM = HS256 ACCESS_TOKEN_EXPIRE_MINUTES = 10 diff --git a/.github/workflows/cd.dev.yml b/.github/workflows/cd.dev.yml new file mode 100644 index 000000000..74bd6a44e --- /dev/null +++ b/.github/workflows/cd.dev.yml @@ -0,0 +1,36 @@ +name: Dev Branch Deployment + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + branches: [dev] + +jobs: + on-success: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use SSH Action + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + cd python/dev_source_code/ + git pull origin dev + source .venv/bin/activate + pip install -r requirements.txt + + + + on-failure: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - run: echo 'The triggering workflow failed' diff --git a/.github/workflows/cd.prod.yml b/.github/workflows/cd.prod.yml new file mode 100644 index 000000000..21a26eba3 --- /dev/null +++ b/.github/workflows/cd.prod.yml @@ -0,0 +1,36 @@ +name: Dev Branch Deployment + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + branches: [main] + +jobs: + on-success: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use SSH Action + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + cd python/prod_source_code/ + git pull origin main + source .venv/bin/activate + pip install -r requirements.txt + + + + on-failure: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - run: echo 'The triggering workflow failed' diff --git a/.github/workflows/cd.staging.yml b/.github/workflows/cd.staging.yml new file mode 100644 index 000000000..01653a2a7 --- /dev/null +++ b/.github/workflows/cd.staging.yml @@ -0,0 +1,36 @@ +name: Dev Branch Deployment + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + branches: [staging] + +jobs: + on-success: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use SSH Action + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + cd python/staging_source_code/ + git pull origin staging + source .venv/bin/activate + pip install -r requirements.txt + + + + on-failure: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - run: echo 'The triggering workflow failed' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..c36e7b435 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: [main, staging, dev] + pull_request: + branches: [main, staging, dev] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: + POSTGRES_PASSWORD: + POSTGRES_DB: + ports: + - 5432:5432 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.9" + virtual-environment: venv + + - name: Install dependencies + run: | + pip install -r requirements.txt + + # - name: Copy env file + # run: cp .env.sample .env + + # - name: Copy env file for main + # if: github.ref == 'refs/heads/main' + # run: cp .env.production .env + + # - name: Copy env file for staging + # if: github.ref == 'refs/heads/staging' + # run: cp .env.staging .env + + # - name: Run migrations + # run: | + # activate + # alembic upgrade head + + # - name: Run tests + # run: | + # activate + # pytest diff --git a/requirements.txt b/requirements.txt index 7326d8865..3b4bb4a4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ bcrypt passlib pymysql uuid7 +psycopg2-binary \ No newline at end of file