Skip to content

Commit

Permalink
add docker workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cullenwatson committed Aug 28, 2023
1 parent 9eb14a7 commit 893894c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Push Docker Image

on:
push:
branches:
- docker_workflow

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and Push Image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/${{ github.repository }}/jobspy_api:latest

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.sha }}
release_name: Release ${{ github.sha }}
draft: false
prerelease: false

- name: Attach Docker Image to Release
run: |
echo "Image ghcr.io/${{ github.repository }}/jobspy_api:latest is available under assets in the release."
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.10-slim

WORKDIR /app

COPY . /app

RUN apt-get update && \
apt-get install -y jq && \
pip install --no-cache-dir -r requirements.txt

EXPOSE 8000

ENV PORT=8000

CMD sh -c "uvicorn main:app --host 0.0.0.0 --port $PORT"
18 changes: 12 additions & 6 deletions api/core/formatters/csv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import gspread
from oauth2client.service_account import ServiceAccountCredentials

import json
import csv
from io import StringIO

import gspread
from google.oauth2.service_account import Credentials
from datetime import datetime


from ...jobs import *
from ...scrapers import *
from settings import *
Expand All @@ -19,9 +21,13 @@ def upload_to_google_sheet(csv_data: str):
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive",
]
credentials = ServiceAccountCredentials.from_json_keyfile_name(
GSHEET_JSON_KEY_PATH, scope
)
if not GSHEET_SECRET_JSON:
raise ValueError("GSHEET_SECRET_JSON not provided!")

secret_dict = json.loads(GSHEET_SECRET_JSON)

credentials = Credentials.from_service_account_info(secret_dict, scopes=scope)

gc = gspread.authorize(credentials)
sh = gc.open(GSHEET_NAME)

Expand Down
8 changes: 4 additions & 4 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os

load_dotenv()
# gsheets (template to copy at https://docs.google.com/spreadsheets/d/1HAnn-aPv-BO4QTEzfIWc-5iw50duyMoTgX8o3RsEOWs/edit?usp=sharing)
GSHEET_JSON_KEY_PATH = "client_secret.json"
GSHEET_NAME = "JobSpy"
# Google sheets output_format
GSHEET_NAME = os.environ.get("GSHEET_NAME", "JobSpy")
GSHEET_SECRET_JSON = os.environ.get("GSHEET_SECRET_JSON")

# optional autha
# optional auth
AUTH_REQUIRED = False
SUPABASE_URL = os.environ.get("SUPABASE_URL")
SUPABASE_KEY = os.environ.get("SUPABASE_KEY")
Expand Down

0 comments on commit 893894c

Please sign in to comment.