Delete the hostedtoolcache folder to free up space #122
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: Continuous Integration and Delivery | |
on: [push] | |
env: | |
WEB_IMAGE: ghcr.io/$(echo $GITHUB_ACTOR | tr '[A-Z]' '[a-z]')/web | |
WORKER_IMAGE: ghcr.io/$(echo $GITHUB_ACTOR | tr '[A-Z]' '[a-z]')/worker | |
jobs: | |
test: | |
name: Test and check quality | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build and run containers | |
run: docker-compose up -d | |
- name: Wait for database | |
run: sleep 30 | |
- name: Apply database migrations | |
run: docker-compose exec -T web alembic upgrade head | |
- name: Check for pending database schema upgrade | |
run: docker-compose exec -T web alembic check | |
- name: Check code linting with ruff | |
run: docker-compose exec -T -u root web ruff check . | |
- name: Check code formatting with black | |
run: docker-compose exec -T -u root web black --check . | |
- name: Test code with pytest | |
run: docker-compose exec -T -u root web pytest -n auto . | |
- name: Cleanup | |
run: docker-compose down -v | |
build-and-deploy: | |
name: Build Docker Images and Deploy to Heroku | |
runs-on: ubuntu-latest | |
needs: [test] | |
env: | |
HEROKU_APP_NAME: fastapi-tdd-docker-spyker77 | |
HEROKU_REGISTRY_WEB_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web | |
HEROKU_REGISTRY_WORKER_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/worker | |
steps: | |
- name: Delete the tools folder to free up space for CUDA | |
run: rm -rf /opt/hostedtoolcache | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Log in to GitHub Packages | |
run: echo ${GITHUB_TOKEN} | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull images | |
run: | | |
docker pull ${{ env.WEB_IMAGE }}-builder:latest || true | |
docker pull ${{ env.WORKER_IMAGE }}-builder:latest || true | |
docker pull ${{ env.WEB_IMAGE }}-cuda-devel:latest || true | |
docker pull ${{ env.WORKER_IMAGE }}-cuda-devel:latest || true | |
docker pull ${{ env.WEB_IMAGE }}-final:latest || true | |
docker pull ${{ env.WORKER_IMAGE }}-final:latest || true | |
- name: Build images | |
run: | | |
# Build Builder Stage | |
docker build \ | |
--target builder \ | |
--cache-from ${{ env.WEB_IMAGE }}-builder:latest \ | |
--tag ${{ env.WEB_IMAGE }}-builder:latest \ | |
--file ./Dockerfile.web \ | |
"." | |
docker build \ | |
--target builder \ | |
--cache-from ${{ env.WORKER_IMAGE }}-builder:latest \ | |
--tag ${{ env.WORKER_IMAGE }}-builder:latest \ | |
--file ./Dockerfile.worker \ | |
"." | |
# Build CUDE-Devel Stage | |
docker build \ | |
--target cuda_devel \ | |
--cache-from ${{ env.WEB_IMAGE }}-cuda-devel:latest \ | |
--tag ${{ env.WEB_IMAGE }}-cuda-devel:latest \ | |
--file ./Dockerfile.web \ | |
"." | |
docker build \ | |
--target cuda_devel \ | |
--cache-from ${{ env.WORKER_IMAGE }}-cuda-devel:latest \ | |
--tag ${{ env.WORKER_IMAGE }}-cuda-devel:latest \ | |
--file ./Dockerfile.worker \ | |
"." | |
# Build Final Stage | |
docker build \ | |
--cache-from ${{ env.WEB_IMAGE }}-final:latest \ | |
--tag ${{ env.WEB_IMAGE }}-final:latest \ | |
--tag ${{ env.HEROKU_REGISTRY_WEB_IMAGE }}:latest \ | |
--file ./Dockerfile.web \ | |
"." | |
docker build \ | |
--cache-from ${{ env.WORKER_IMAGE }}-final:latest \ | |
--tag ${{ env.WORKER_IMAGE }}-final:latest \ | |
--tag ${{ env.HEROKU_REGISTRY_WORKER_IMAGE }}:latest \ | |
--file ./Dockerfile.worker \ | |
"." | |
- name: Push images to the packages | |
run: | | |
docker push ${{ env.WEB_IMAGE }}-builder:latest | |
docker push ${{ env.WORKER_IMAGE }}-builder:latest | |
docker push ${{ env.WEB_IMAGE }}-cuda-devel:latest | |
docker push ${{ env.WORKER_IMAGE }}-cuda-devel:latest | |
docker push ${{ env.WEB_IMAGE }}-final:latest | |
docker push ${{ env.WORKER_IMAGE }}-final:latest | |
# 🚨 Disable continuous delivery to Heroku 🚨 | |
# - name: Log in to the Heroku Container Registry | |
# run: docker login -u _ -p ${HEROKU_AUTH_TOKEN} registry.heroku.com | |
# env: | |
# HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }} | |
# - name: Push images to the registry | |
# run: | | |
# docker push ${{ env.HEROKU_REGISTRY_WEB_IMAGE }}:latest | |
# docker push ${{ env.HEROKU_REGISTRY_WORKER_IMAGE }}:latest | |
# - name: Set environment variables | |
# run: | | |
# echo "HEROKU_REGISTRY_WEB_IMAGE=${{ env.HEROKU_REGISTRY_WEB_IMAGE }}" >> $GITHUB_ENV | |
# echo "HEROKU_REGISTRY_WORKER_IMAGE=${{ env.HEROKU_REGISTRY_WORKER_IMAGE }}" >> $GITHUB_ENV | |
# echo "HEROKU_AUTH_TOKEN=${{ secrets.HEROKU_AUTH_TOKEN }}" >> $GITHUB_ENV | |
# - name: Release | |
# run: | | |
# chmod +x ./scripts/release.sh | |
# ./scripts/release.sh |