66 - Upload Form in Item Detail View #20
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: Django Buildpack | |
on: | |
push: | |
branches: [main] | |
paths: | |
- 'src/**' | |
pull_request: | |
branches: [main] | |
paths: | |
- 'src/**' | |
workflow_dispatch: | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
env: | |
BASE_DIR: ${{ secrets.BASE_DIR || 'src/' }} | |
# Disable Django's collectstatic command by default | |
DISABLE_COLLECTSTATIC: ${{ secrets.DISABLE_COLLECTSTATIC || 1 }} | |
# Default to 'gcr.io/buildpacks/builder' if BUILDPACK_BUILDER secret is not set. | |
# https://cloud.google.com/docs/buildpacks/builders | |
BUILDPACK_BUILDER: ${{ secrets.BUILDPACK_BUILDER || 'gcr.io/buildpacks/builder' }} | |
# Docker Image Tag, default to GitHub sha if not set | |
DOCKER_HUB_IMAGE_TAG: ${{ secrets.DOCKER_HUB_IMAGE_TAG || github.sha }} | |
# Default DOCKER_REPO to GitHub's username/repository if not provided as a secret | |
DOCKER_HUB_REPO: ${{ secrets.DOCKER_HUB_REPO || github.repository }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install requirements & collectstatic | |
run: | | |
cd ${{ env.BASE_DIR }} | |
python3 -m pip install -r requirements.txt | |
python3 manage.py collectstatic --no-input | |
- name: Setup Pack CLI | |
uses: buildpacks/github-actions/[email protected] | |
- name: Build app using Buildpacks | |
run: | | |
pack build ${{ env.DOCKER_HUB_REPO }}:${{ env.DOCKER_HUB_IMAGE_TAG }} \ | |
--path ${{ env.BASE_DIR }} \ | |
--env "DISABLE_COLLECTSTATIC=1" \ | |
--builder ${{ env.BUILDPACK_BUILDER }} | |
- name: Login to Docker Hub | |
id: docker_login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Check Docker Login | |
if: steps.docker_login.outcome == 'failure' | |
run: | | |
echo "Failed to log in to Docker Hub. Please check your credentials." | |
exit 1 | |
- name: Tag the container as latest as well specific version | |
run: | | |
docker tag ${{ env.DOCKER_HUB_REPO }}:${{ env.DOCKER_HUB_IMAGE_TAG }} ${{ env.DOCKER_HUB_REPO }}:latest | |
- name: Push the specific version and latest tag to Docker Hub | |
run: docker push ${{ env.DOCKER_HUB_REPO }} --all-tags |