Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Docker image from github CI #1

Merged
merged 12 commits into from
Jan 16, 2025
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
100 changes: 100 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build and Publish Presidio Analyzer Docker Image 🐳

on:
push:
branches:
- main
workflow_dispatch: # Manual trigger only

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

jobs:
build-and-publish:
name: Build and Publish Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest

- name: Build and Push Docker Image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-to: type=inline

- 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

service-test:
name: Test Docker Image
needs: build-and-publish
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

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

- name: Install Test Dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip curl
pip3 install pytest requests

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and Test Docker Image
run: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker run -d --name presidio -p 8080:8080 -e PORT=8080 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
sleep 60
docker ps
docker logs presidio

curl http://localhost:8080/health
pytest tests/test_service.py -s
53 changes: 0 additions & 53 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ RUN apt-get update && apt-get install -y build-essential curl

# next line is required to install the CPU version of Torch and not the GPU one, see
# https://pytorch.org/get-started/locally/
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu
RUN pip install uv==0.2.2
ENV VIRTUAL_ENV=/usr/local
RUN uv pip sync requirements.txt --python=/usr/local/bin/python && uv cache clean
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu

COPY . .

Expand Down
Loading