Skip to content

Commit

Permalink
build: add GH action job for publishing docker image to registry (#110)
Browse files Browse the repository at this point in the history
* build: add GH action job for publishing docker image to registry

* style: update action name

* build: add linux/arm64 platform
  • Loading branch information
anujsinha3 authored Oct 9, 2024
1 parent 7098ea9 commit 4b48c0c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/cd_support_sphere_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ concurrency:

env:
FORCE_COLOR: 3
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
dist:
Expand Down Expand Up @@ -93,3 +95,39 @@ jobs:

- uses: pypa/gh-action-pypi-publish@v1.9.0
if: startsWith(github.ref, 'refs/tags')

push_to_registry:
name: Push Docker image to GH Container Registry
needs: [test-built-dist]
runs-on: ubuntu-latest
steps:
- name: Delay for PyPI
run: sleep 5 # Wait for the package to be available in PyPI
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Log in to registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./deployment/docker/
file: ./deployment/docker/populate_db.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
build-args: VERSION=${{needs.test-built-dist.outputs.package-version}}
8 changes: 2 additions & 6 deletions deployment/docker/populate_db.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ FROM python:3.12-slim
# Set the working directory inside the container
WORKDIR /app

# Copy the Python script and requirements file into the container
COPY ../../src/support_sphere_py /app/support_sphere_py


# Below ENV values are overridden when running the via K8s Job else the above arg values are used.
ENV DB_HOST=localhost
ENV DB_PORT=5432
Expand All @@ -19,7 +15,7 @@ ENV JWT_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm


# Install any necessary dependencies
RUN pip install --no-cache-dir ./support_sphere_py
RUN pip3 install --no-cache-dir --extra-index-url https://test.pypi.org/simple --only-binary=:all: support_sphere_py

# Command to run the Python script
ENTRYPOINT ["sh", "-c", "python3 ./support_sphere_py/tests/resources/scripts/role_based_access_control.py && python3 ./support_sphere_py/tests/resources/scripts/update_db_sample_data.py"]
ENTRYPOINT ["sh", "-c", "python3 -m support_sphere.tests.resources.scripts.role_based_access_control && python3 -m support_sphere.tests.resources.scripts.update_db_sample_data"]
25 changes: 25 additions & 0 deletions deployment/docker/populate_db_dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.12-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the Python script and requirements file into the container
COPY ../../src/support_sphere_py /app/support_sphere_py


# Below ENV values are overridden when running the via K8s Job else the above arg values are used.
ENV DB_HOST=localhost
ENV DB_PORT=5432
ENV DB_USERNAME=postgres
ENV DB_PASSWORD=example123456
ENV DB_NAME=postgres
ENV SUPABASE_KONG_HOST=supabase-supabase-kong
ENV SUPABASE_KONG_PORT=8000
ENV JWT_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE


# Install any necessary dependencies
RUN pip install --no-cache-dir ./support_sphere_py

# Command to run the Python script
ENTRYPOINT ["sh", "-c", "python3 ./support_sphere_py/tests/resources/scripts/role_based_access_control.py && python3 ./support_sphere_py/tests/resources/scripts/update_db_sample_data.py"]
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ setup-db-data-via-k8s-job = { depends-on = [
]}

[feature.db.tasks.build-docker-image-for-api-service]
cmd = "docker build -t pdc/populate_db:1.0 -f deployment/docker/populate_db.Dockerfile ."
cmd = "docker build -t pdc/populate_db:1.0 -f deployment/docker/populate_db_dev.Dockerfile ."

[feature.db.tasks.import-docker-image-in-k8s-cluster]
cmd = "k3d image import pdc/populate_db:1.0 -c pdc-cluster"
Expand Down
2 changes: 1 addition & 1 deletion src/support_sphere_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-backend = "hatchling.build"

[project]
name = "support-sphere-py"
version = "0.0.8"
version = "0.0.12"
description = "Package for support sphere api service"
readme = "README.md"
requires-python = ">=3.12"
Expand Down

0 comments on commit 4b48c0c

Please sign in to comment.