Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build Docker image

on:
push:
branches:
- build_image
tags:
- 'v*.*.*'

env:
GH_REGISTRY: ghcr.io
GH_NAMESPACE: oceanum-io
GAR_REGISTRY: us-central1-docker.pkg.dev
GAR_PROJECT: oceanum-registry
GAR_REPOSITORY: public
IMAGE_NAME: oceanum-python
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12, 3.13]
debian-version: [bookworm, trixie]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Split Versions
id: split_versions
run: |
MAJOR_VERSION=$(echo ${{ github.ref_name }} | cut -d. -f1)
MINOR_VERSION=$(echo ${{ github.ref_name }} | cut -d. -f2)
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
echo "MINOR_VERSION=$MINOR_VERSION" >> $GITHUB_ENV

- name: Login to GAR
uses: docker/login-action@v3
with:
registry: ${{ env.GAR_REGISTRY }}
username: ${{ vars.GCP_AR_DOCKER_USERNAME }}
password: ${{ secrets.GCP_AR_DOCKER_PASSWORD }}

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.GH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v6
with:
#platforms: linux/amd64
context: .
file: Dockerfile
cache-from: type=registry,ref=${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}-cache
cache-to: type=registry,ref=${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}-cache
build-args: |
PYTHON_VER=${{ matrix.python-version }}
DEBIAN_VER=${{ matrix.debian-version }}
push: true
tags: |
${{ env.GH_REGISTRY }}/${{ env.GH_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
${{ env.GH_REGISTRY }}/${{ env.GH_NAMESPACE }}/${{ env.IMAGE_NAME }}:py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GH_REGISTRY }}/${{ env.GH_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.MINOR_VERSION }}-py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GH_REGISTRY }}/${{ env.GH_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.MINOR_VERSION }}.${{ env.MAJOR_VERSION }}-py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GH_REGISTRY }}/${{ env.GH_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:latest
${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.MINOR_VERSION }}-py${{ matrix.python-version }}-${{ matrix.debian-version }}
${{ env.GAR_REGISTRY }}/${{ env.GAR_PROJECT }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.MINOR_VERSION }}.${{ env.MAJOR_VERSION }}-py${{ matrix.python-version }}-${{ matrix.debian-version }}
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG PYTHON_VER=3.12
ARG DEBIAN_VER=trixie
FROM python:${PYTHON_VER}-slim-${DEBIAN_VER}

LABEL org.opencontainers.image.description="oceanum-python: A Python library and CLI for Oceanum.io services."
LABEL org.opencontainers.image.source="https://github.com/oceanum-io/oceanum-python"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.vendor="Oceanum.io"
LABEL org.opencontainers.image.title="oceanum-python"
LABEL org.opencontainers.image.authors="Oceanum Developers"

RUN apt-get update &&\
apt-get install -y --no-install-recommends build-essential gcc gdal-bin gdal-data libgdal-dev &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/*

RUN useradd -u 1001 -p oceanum --create-home --shell=/bin/bash oceanum

USER oceanum
WORKDIR /home/oceanum
ENV PIP_NO_CACHE_DIR=1
RUN python -m venv .venv/oceanum

# Set environment variables to activate the virtual environment globally
ENV VIRTUAL_ENV="/home/oceanum/.venv/oceanum"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
SHELL ["/bin/bash", "-c"]

# Install dependencies first
COPY --chown=oceanum:oceanum pyproject.toml /home/oceanum/oceanum-python/
RUN pip install -U pip pip-tools &&\
pip-compile /home/oceanum/oceanum-python/pyproject.toml &&\
pip install -r /home/oceanum/oceanum-python/requirements.txt

# Now copy the rest of the code
COPY --chown=oceanum:oceanum . /home/oceanum/oceanum-python/
WORKDIR /home/oceanum/oceanum-python
# Install the package (virtual environment is automatically activated via ENV variables)
RUN pip install -e .
ENTRYPOINT ["oceanum"]