Update dependencies #417
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: Build, Test & Deploy | |
on: [push, pull_request] | |
env: | |
DOCKER_IMAGE_NAME: ghcr.io/beeracademy/web | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup python environment | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.12" | |
- name: Install python dependencies | |
run: pip install -r requirements.txt -r dev-requirements.txt | |
- name: Run pre-commit checks | |
uses: pre-commit/action@v3.0.0 | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Pull existing images | |
run: docker compose pull | |
- name: Build image | |
run: ./build | |
- name: Save docker image | |
run: docker save "$DOCKER_IMAGE_NAME" | gzip > image.tar.gz | |
- name: Upload docker image for other jobs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: image | |
path: image.tar.gz | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
- name: Load docker image | |
run: docker load < image.tar.gz | |
- name: Run tests | |
run: docker run --env DJANGO_SETTINGS_MODULE=academy.settings.development "$DOCKER_IMAGE_NAME" ./manage.py test | |
test-postgres: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Download docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
- name: Load docker image | |
run: docker load < image.tar.gz | |
- name: Run tests using postgres | |
run: USE_DOCKER=1 ./test_postgres | |
test-docker-compose: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Download docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
- name: Load docker image | |
run: docker load < image.tar.gz | |
- name: Test docker compose | |
run: | | |
for k in "SECRET_KEY" "EMAIL_HOST_PASSWORD" "FACEBOOK_ACCESS_TOKEN"; do | |
echo "$k=foo" >> ".env" | |
done | |
docker network create traefik | |
docker compose up -d | |
sleep 10 | |
res=$(docker compose ps) | |
echo "$res" | |
if echo "$res" | grep Exit &>/dev/null; then | |
exit 1 | |
fi | |
release: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/master' | |
needs: | |
- pre-commit | |
- build | |
- test | |
- test-postgres | |
- test-docker-compose | |
steps: | |
- name: Download docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
- name: Load docker image | |
run: docker load < image.tar.gz | |
- name: Publish image to ghcr.io | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username "${{ github.actor }}" --password-stdin | |
docker push "$DOCKER_IMAGE_NAME" | |
deploy: | |
runs-on: ubuntu-latest | |
needs: release | |
steps: | |
- name: Deploy image to production | |
run: curl --fail -X POST "$WEBHOOK_URL" | |
env: | |
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} |