-
-
Save emorozov/3edc74b47895c421f0c5825ae928986b 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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