Skip to content

Commit

Permalink
Feature/49 migrate to gcp (#50)
Browse files Browse the repository at this point in the history
* Added docker setup #49

* Added new pipeline for GCP deploy #49

* Optimized dependencies for containerization #49

* Implemented waitress to host production WSGI HTTP server #49

* Update pipeline to move away from google cloud build #49

* Remove aws files #49

* Test fix attempt #49
  • Loading branch information
zachale authored Oct 26, 2024
1 parent dd771c6 commit 3c40ed2
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 938 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.github
.git
.gitignore
.dockerignore
Dockerfile
.ruff_cache
.venv
aws
tests
.env
.pre-commit-config.yaml
Makefile
poetry.toml
73 changes: 18 additions & 55 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,26 @@
name: Deploy Pipeline
on: [workflow_dispatch]
on:
workflow_dispatch:
push:
branches:
- main
env:
REGION: us-central1
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Authenticate to Google Cloud
uses: "google-github-actions/auth@v2"
with:
python-version: "3.12"
cache: "pip"
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Display AWS CLI version
run: aws --version
- name: Restore cached .venv
uses: actions/cache/restore@v4
id: cache-venv
with:
key: venv-${{ runner.os }}-${{ hashFiles('poetry.lock') }}
path: .venv
- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config --list
- name: Install dependencies
if: steps.cache-venv.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Cache .venv
if: steps.cache-venv.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: venv-${{ runner.os }}-${{ hashFiles('poetry.lock') }}
path: .venv
- name: Create .env
uses: SpicyPizza/create-envfile@v2.0
with:
envkey_DEV: "dev"
envkey_MONGO_TOKEN: ${{ secrets.MONGO_TOKEN }}
file_name: .env
- name: AWS Setup
run: |
mkdir -p ~/.aws
cat > ~/.aws/config << EOF
[profile dev]
role_arn = ${{ secrets.LAMBDA_ARN }}
source_profile = default
EOF
cat > ~/.aws/credentials << EOF
[default]
aws_access_key_id = ${{ secrets.DEV_ID }}
aws_secret_access_key = ${{ secrets.DEV_KEY }}
EOF
- name: Build Lambda code
run: poetry run python aws/build_lambda_code.py
- name: Deploy stack
shell: bash
run: |
chmod +x ./aws/deploy.sh
./aws/deploy.sh ${{ secrets.MONGO_TOKEN }}
wait
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- name: Configure Docker
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: Build Docker Container
run: docker build . -t ${{ secrets.CONTAINER_IMAGE_URL }}
- name: Push Docker Container to Google Cloud
run: docker push ${{ secrets.CONTAINER_IMAGE_URL }}
- name: Deploy Container to Google Cloud Run
run: gcloud run deploy imaginate-api --image ${{ secrets.CONTAINER_IMAGE_URL }} --region ${{ env.REGION }}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.12-slim
RUN pip install poetry==1.8.4
WORKDIR /api
COPY . .
RUN poetry install --without dev --sync
CMD ["poetry","run","python", "imaginate_api/app.py"]


38 changes: 0 additions & 38 deletions aws/SETUP.md

This file was deleted.

95 changes: 0 additions & 95 deletions aws/billing.yml

This file was deleted.

113 changes: 0 additions & 113 deletions aws/build_lambda_code.py

This file was deleted.

35 changes: 0 additions & 35 deletions aws/deploy.sh

This file was deleted.

Loading

0 comments on commit 3c40ed2

Please sign in to comment.