From 46cd17fdd57336bb6517ffc30c3a0522b1cf0727 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Fri, 31 May 2024 20:28:24 +0000 Subject: [PATCH 1/4] Modify Dockerfile for portability and add publishing workflow --- .github/workflows/docker_image.yml | 32 +++++++++++++++++++++++++++ dev/{django.Dockerfile => Dockerfile} | 13 +++++------ docker-compose.override.yml | 8 +++---- 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/docker_image.yml rename dev/{django.Dockerfile => Dockerfile} (52%) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml new file mode 100644 index 00000000..16a451c0 --- /dev/null +++ b/.github/workflows/docker_image.yml @@ -0,0 +1,32 @@ +name: Publish Docker Packages +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: OpenGeoscience/uvdat:server + +jobs: + publish-uvdat-server: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Log into the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: token + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push the Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: dev/Dockerfile + push: ${{ github.actor != 'dependabot[bot]' }} + tags: ${{ env.IMAGE_NAME }} diff --git a/dev/django.Dockerfile b/dev/Dockerfile similarity index 52% rename from dev/django.Dockerfile rename to dev/Dockerfile index ae6dc4c2..6507669a 100644 --- a/dev/django.Dockerfile +++ b/dev/Dockerfile @@ -1,6 +1,5 @@ FROM python:3.10-slim # Install system libraries for Python packages: -# * psycopg2 RUN apt-get update && \ apt-get install --no-install-recommends --yes \ libpq-dev libvips-dev gcc libc6-dev gdal-bin git && \ @@ -9,13 +8,11 @@ RUN apt-get update && \ ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -# Only copy the setup.py, it will still force all install_requires to be installed, -# but find_packages() will find nothing (which is fine). When Docker Compose mounts the real source -# over top of this directory, the .egg-link in site-packages resolves to the mounted directory -# and all package modules are importable. -COPY ./setup.py /opt/django-project/setup.py +COPY ./setup.py /opt/uvdat-server/setup.py +COPY ./manage.py /opt/uvdat-server/manage.py +COPY ./uvdat /opt/uvdat-server/uvdat RUN pip install large-image[gdal,pil] large-image-converter --find-links https://girder.github.io/large_image_wheels -RUN pip install --editable /opt/django-project[dev] +RUN pip install --editable /opt/uvdat-server[dev] # Use a directory name which will never be an import name, as isort considers this as first-party. -WORKDIR /opt/django-project +WORKDIR /opt/uvdat-server diff --git a/docker-compose.override.yml b/docker-compose.override.yml index d0516331..90d28ec1 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -3,13 +3,13 @@ services: django: build: context: . - dockerfile: ./dev/django.Dockerfile + dockerfile: ./dev/Dockerfile command: [ "./manage.py", "runserver", "0.0.0.0:8000" ] # Log printing via Rich is enhanced by a TTY tty: true env_file: ./dev/.env.docker-compose volumes: - - .:/opt/django-project + - .:/opt/uvdat-server ports: - 8000:8000 depends_on: @@ -20,7 +20,7 @@ services: celery: build: context: . - dockerfile: ./dev/django.Dockerfile + dockerfile: ./dev/Dockerfile command: [ "celery", @@ -35,7 +35,7 @@ services: tty: false env_file: ./dev/.env.docker-compose volumes: - - .:/opt/django-project + - .:/opt/uvdat-server depends_on: - postgres - rabbitmq From bf55c7b039b8018769041b5b32b7cfa76d1b5422 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Fri, 31 May 2024 20:30:49 +0000 Subject: [PATCH 2/4] Modify image name (must be all lowercase) --- .github/workflows/docker_image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 16a451c0..15406e96 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -8,7 +8,7 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: OpenGeoscience/uvdat:server + IMAGE_NAME: uvdat/uvdat:server jobs: publish-uvdat-server: From 25462766a452cb3c5929c952c6615848717a15b6 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Wed, 5 Jun 2024 14:27:42 +0000 Subject: [PATCH 3/4] Prepend tag with registry URL --- .github/workflows/docker_image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 15406e96..4af277ae 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -8,7 +8,7 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: uvdat/uvdat:server + IMAGE_NAME: opengeoscience/uvdat:server jobs: publish-uvdat-server: @@ -29,4 +29,4 @@ jobs: context: . file: dev/Dockerfile push: ${{ github.actor != 'dependabot[bot]' }} - tags: ${{ env.IMAGE_NAME }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} From 52ba359fb4ae0a8c1a551f1123d287bbfeb2f3bd Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Wed, 12 Jun 2024 13:07:04 +0000 Subject: [PATCH 4/4] Add python semantic versioning step to generate tag for image --- .../workflows/{docker_image.yml => release.yml} | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) rename .github/workflows/{docker_image.yml => release.yml} (63%) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/release.yml similarity index 63% rename from .github/workflows/docker_image.yml rename to .github/workflows/release.yml index 4af277ae..db9529d4 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,28 @@ -name: Publish Docker Packages +name: Release on: workflow_dispatch: push: branches: - master - pull_request: env: REGISTRY: ghcr.io - IMAGE_NAME: opengeoscience/uvdat:server + IMAGE_NAME: opengeoscience/uvdat-server jobs: - publish-uvdat-server: + tag-and-publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 + + - name: Python Semantic Release + id: release + uses: python-semantic-release/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Log into the Container registry uses: docker/login-action@v2 with: @@ -29,4 +35,4 @@ jobs: context: . file: dev/Dockerfile push: ${{ github.actor != 'dependabot[bot]' }} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.release.outputs.tag }}