From 06f6d8bcc5c478ae140413f0e0f86272d5a6a28c Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:10:34 +0800 Subject: [PATCH 1/6] Test --- .../workflows/dockerhub-django-ninja-api.yml | 57 +++++++++++++++++++ .../django-ninja-api/docker/dockerfile-hub | 18 ++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/dockerhub-django-ninja-api.yml create mode 100644 backend/django-ninja-api/docker/dockerfile-hub diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml new file mode 100644 index 0000000..5088248 --- /dev/null +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -0,0 +1,57 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Push Docker image to Docker Hub + +on: + push: + # branches: + # - main + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: my-docker-hub-namespace/my-docker-hub-repository + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: backend/django-ninja-api/docker/dockerfile-hub + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/backend/django-ninja-api/docker/dockerfile-hub b/backend/django-ninja-api/docker/dockerfile-hub new file mode 100644 index 0000000..8afb5a2 --- /dev/null +++ b/backend/django-ninja-api/docker/dockerfile-hub @@ -0,0 +1,18 @@ +FROM python:3.12.5-bullseye + +# Basis +RUN apt-get update -y +RUN apt-get install -y build-essential +RUN apt-get install -y libpq-dev + +RUN pip install --upgrade pip +RUN pip install django==5.1 +RUN pip install django-ninja +RUN pip install django-ninja-jwt +RUN pip install django-cors-headers +RUN pip install django-redis +RUN pip install orjson +RUN pip install uvicorn + +RUN pip install "psycopg[binary]" +RUN pip install python-dotenv \ No newline at end of file From 6ede56bdcc2e275973d8388a83fed9bedaa31506 Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:19:21 +0800 Subject: [PATCH 2/6] Test username --- .github/workflows/dockerhub-django-ninja-api.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml index 5088248..db781a9 100644 --- a/.github/workflows/dockerhub-django-ninja-api.yml +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -27,6 +27,9 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 + - name: Install dependencies + run: echo ${{ secrets.DOCKER_USERNAME }} + - name: Log in to Docker Hub uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: @@ -37,7 +40,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: my-docker-hub-namespace/my-docker-hub-repository + images: ansoncar/django-ninja-api-basis - name: Build and push Docker image id: push From b816862fea551f64d6251173466ad164651099ec Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:28:17 +0800 Subject: [PATCH 3/6] Test --- .github/workflows/dockerhub-django-ninja-api.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml index db781a9..25d1a7a 100644 --- a/.github/workflows/dockerhub-django-ninja-api.yml +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -40,7 +40,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ansoncar/django-ninja-api-basis + images: ansoncar/django-ninja-api-basis:v0.7.0 - name: Build and push Docker image id: push @@ -52,9 +52,9 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Generate artifact attestation - uses: actions/attest-build-provenance@v1 - with: - subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} - subject-digest: ${{ steps.push.outputs.digest }} - push-to-registry: true + # - name: Generate artifact attestation + # uses: actions/attest-build-provenance@v1 + # with: + # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + # subject-digest: ${{ steps.push.outputs.digest }} + # push-to-registry: true From b7c7a61bd130adec36621d444e7582a6d1de1852 Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:29:08 +0800 Subject: [PATCH 4/6] feat:add tag --- .github/workflows/dockerhub-django-ninja-api.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml index 25d1a7a..d5d47dc 100644 --- a/.github/workflows/dockerhub-django-ninja-api.yml +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -41,6 +41,7 @@ jobs: uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: images: ansoncar/django-ninja-api-basis:v0.7.0 + tags: true - name: Build and push Docker image id: push From 5fac9ba76d7cb2de2808d09b1351f91fdb478d08 Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:30:08 +0800 Subject: [PATCH 5/6] feat: add labels --- .github/workflows/dockerhub-django-ninja-api.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml index d5d47dc..220bae3 100644 --- a/.github/workflows/dockerhub-django-ninja-api.yml +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -40,8 +40,9 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ansoncar/django-ninja-api-basis:v0.7.0 - tags: true + images: ansoncar/django-ninja-api-basis + tags: v0.7.0 + labels: v0.7.0 - name: Build and push Docker image id: push From b565a962a8c6087b61ea19733ea3375b6ae26aca Mon Sep 17 00:00:00 2001 From: AnsonCar Date: Sun, 8 Sep 2024 20:36:03 +0800 Subject: [PATCH 6/6] Test v0.8.0 --- .github/workflows/dockerhub-django-ninja-api.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dockerhub-django-ninja-api.yml b/.github/workflows/dockerhub-django-ninja-api.yml index 220bae3..c84ebb0 100644 --- a/.github/workflows/dockerhub-django-ninja-api.yml +++ b/.github/workflows/dockerhub-django-ninja-api.yml @@ -11,8 +11,8 @@ name: Push Docker image to Docker Hub on: push: - # branches: - # - main + branches: + - main jobs: push_to_registry: @@ -23,6 +23,8 @@ jobs: contents: read attestations: write id-token: write + env: + IMAGE_VERSION: v0.7.0 steps: - name: Check out the repo uses: actions/checkout@v4 @@ -41,8 +43,8 @@ jobs: uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: images: ansoncar/django-ninja-api-basis - tags: v0.7.0 - labels: v0.7.0 + tags: ${{ env.IMAGE_VERSION }} + labels: ${{ env.IMAGE_VERSION }} - name: Build and push Docker image id: push