Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imylomylo/20e3ae10547369c21a14d4eeacba1f7e to your computer and use it in GitHub Desktop.
Save imylomylo/20e3ae10547369c21a14d4eeacba1f7e to your computer and use it in GitHub Desktop.
This is a good starting point for getting Python, Django, Postgres running as a service, pytest, black, and pip caching rolling with GitHub Actions.
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
if: steps.cache.outputs.cache-hit != 'true'
- name: Test with black
run: |
python -m black --check .
- name: Test with pytest
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
run: |
python -m pytest
name: docker-publish
on:
push:
branches:
- master
jobs:
docker:
name: Build and Publish Docker image
runs-on: ubuntu-latest
steps:
- name: Git - Get Sources
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Docker - Build
run: |
docker build . --file .docker/Dockerfile --tag changeme-web
- name: Docker - Login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com --username ${{ github.actor }} --password-stdin
- name: Docker - Tag
run: |
docker tag changeme-web docker.pkg.github.com/${{ github.repository }}/changeme-web:latest
- name: Docker - Push
run: |
docker push docker.pkg.github.com/${{ github.repository }}/changeme-web:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment