Skip to content
Merged
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
107 changes: 107 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Docker Build and Push

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

env:
SERVIZIO_OC: sparontologies
DOCKER_REGISTRY: opencitations

jobs:
docker-build-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Read version from docker_version.txt
id: get_version
run: |
if [ ! -f docker_version.txt ]; then
echo "Error: docker_version.txt file not found"
exit 1
fi
VERSION=$(cat docker_version.txt | tr -d '\n\r' | xargs)
if [ -z "$VERSION" ]; then
echo "Error: empty version in docker_version.txt"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"

- name: Check if image exists on DockerHub
id: check_image
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
run: |
echo "Checking if image exists: ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION}"

# Query DockerHub API to check if tag exists
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
"https://hub.docker.com/v2/repositories/${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}/tags/${VERSION}/")

if [ "$HTTP_CODE" == "200" ]; then
echo "Image already exists on DockerHub"
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "Image not found on DockerHub, will build new one"
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi

- name: Set up Docker Buildx
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
run: |
echo "Building image: ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION}"

# Build image with no cache
docker build --no-cache -t ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION} .
sleep 1

# Tag image
docker tag ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION} ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION}
sleep 1

# Push to registry
echo "Pushing image to DockerHub..."
docker push ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION}
sleep 1

# Check result
if [ $? == 0 ]; then
echo "ALL DONE !"
else
echo "NO NO NOOOOOOO !"
exit 1
fi

- name: Build summary
run: |
VERSION="${{ steps.get_version.outputs.VERSION }}"
IMAGE_EXISTS="${{ steps.check_image.outputs.IMAGE_EXISTS }}"

echo "Build Summary:"
echo "Version: ${VERSION}"
echo "Image: ${{ env.DOCKER_REGISTRY }}/${{ env.SERVIZIO_OC }}:${VERSION}"

if [ "$IMAGE_EXISTS" == "true" ]; then
echo "Status: Image already exists, skipped build"
else
echo "Status: New image built and pushed successfully"
fi
31 changes: 30 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
*.pyc
sparontologies_log.txt
nohup.out
private/
private/


#log folder
log/*
!log/.gitkeep

# Byte-compiled / optimized / DLL files
__pycache__/
src/__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.DS_Store
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Base image: Python slim for a lightweight container
FROM python:3.11-slim

# Define environment variables with default values
# These can be overridden during container runtime
ENV BASE_URL="www.sparontologies.net"

# Ensure Python output is unbuffered
ENV PYTHONUNBUFFERED=1
# Install system dependencies required for Python package compilation
# We clean up apt cache after installation to reduce image size
RUN apt-get update && \
apt-get install -y \
git \
curl \
ca-certificates \
python3-dev \
build-essential

# Install uv for dependency management
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin:$PATH"

# Set the working directory for our application
WORKDIR /website

# Copy the application code from the repository to the container
# The code is already present in the repo, no need to git clone
COPY . .

# Install Python dependencies using uv
RUN uv sync --frozen --no-dev

# Expose the port that our service will listen on
EXPOSE 8080

# Start the application with gunicorn instead of python directly
CMD ["uv", "run", "gunicorn", "-c", "gunicorn.conf.py", "spar:application"]
1 change: 1 addition & 0 deletions docker_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.0
Loading