Skip to content

Instantly share code, notes, and snippets.

@Vichoko
Created May 25, 2023 16:52
Show Gist options
  • Save Vichoko/08cbfb0da5da4f5f32ff04950c2d27eb to your computer and use it in GitHub Desktop.
Save Vichoko/08cbfb0da5da4f5f32ff04950c2d27eb to your computer and use it in GitHub Desktop.
Poetry & Venv Cache
on:
push:
branches:
- main
# only cancel the previous workflow if it is still in progress
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# this workflow will deploy the django application into google app engine
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: 'Checkout'
uses: 'actions/checkout@v3'
- name: 'Set up Python 3.8'
id: 'setup-python'
uses: 'actions/setup-python@v4'
with:
python-version: '3.8'
- name: 'Load cached Poetry installation'
id: 'cached-poetry'
uses: 'actions/cache@v3'
with:
path: /home/runner/.local/
key: poetry-0 # increment to reset cache
- name: 'Install Poetry'
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: 'snok/install-poetry@v1'
with:
virtualenvs-create: false
virtualenvs-in-project: false
installer-parallel: true
- name: 'Load cached venv'
id: 'cached-poetry-dependencies'
uses: 'actions/cache@v3'
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: 'Create Python Virtual Environment'
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
python -m venv .venv
- name: 'Install dependencies'
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
source .venv/bin/activate
poetry install --no-interaction --no-root
- name: 'Collect static files'
run: |
source .venv/bin/activate
poetry run python meridiem/manage.py collectstatic --no-input
- name: 'Build my.cnf'
run: |
mkdir -p mysql
cd mysql
echo "[client]" > my.cnf
echo "user = ${{ secrets.DATABASE_USERNAME }}" >> my.cnf
echo "password = ${{ secrets.DATABASE_PASSWORD }}" >> my.cnf
echo "host = ${{ secrets.DATABASE_HOST }}" >> my.cnf
echo "database = ${{ secrets.DATABASE_NAME }}" >> my.cnf
echo "ssl_mode = VERIFY_IDENTITY" >> my.cnf
echo "ssl_ca = /etc/ssl/certs/ca-certificates.crt" >> my.cnf
- name: 'Export requirements.txt'
run: |
source .venv/bin/activate
poetry export -f requirements.txt --output requirements.txt --without-hashes
- name: 'Authenticate with Google Cloud'
id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.CICD_SA_KEY }}'
- name: 'Deploy to Google App Engine'
id: 'deploy'
uses: 'google-github-actions/deploy-appengine@v1'
- name: 'Migrate database'
run: |
source .venv/bin/activate
poetry run python meridiem/manage.py migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment