diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml new file mode 100644 index 0000000..daa9889 --- /dev/null +++ b/.github/workflows/publish-docker-image.yml @@ -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 \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index a28f8af..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -stages: - - docker-build - - service-test - -job-docker: - stage: docker-build - image: docker:23.0 - services: - - docker:dind - variables: - DOCKER_BUILDKIT: 1 - JOB_IMAGE_TAG: $CI_REGISTRY_IMAGE/presidio-analyzer:$CI_COMMIT_REF_SLUG.$CI_COMMIT_SHA - LATEST_TAG: $CI_REGISTRY_IMAGE/presidio-analyzer:latest - before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - script: - - docker build --network host - --pull - --cache-from $CI_REGISTRY_IMAGE/presidio-analyzer:latest - --cache-from $CI_REGISTRY_IMAGE/presidio-analyzer:$CI_COMMIT_REF_SLUG.$CI_COMMIT_SHA - --build-arg BUILDKIT_INLINE_CACHE=1 - --build-arg FURY_AUTH=$FURY_AUTH - --build-arg VERSION_STRING="$CI_REGISTRY_IMAGE/presidio-analyzer:$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA:$CI_COMMIT_TIMESTAMP" - -f Dockerfile - -t "$JOB_IMAGE_TAG" . - - docker tag "$JOB_IMAGE_TAG" "$LATEST_TAG" # Tagging the image as latest - - docker push "$JOB_IMAGE_TAG" - - docker push "$LATEST_TAG" - when: manual - -job-service: - stage: service-test - image: docker:23.0 - services: - - docker:dind - variables: - JOB_IMAGE_TAG: $CI_REGISTRY_IMAGE/presidio-analyzer:latest - before_script: - - apk add --no-cache python3 py3-pip curl - - pip3 install pytest - - pip3 install requests - script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - - docker pull "$JOB_IMAGE_TAG" - - docker run -d --name presidio -p 8080:8080 -e PORT=8080 "$JOB_IMAGE_TAG" - - sleep 60 - - docker ps - - docker logs presidio - - curl http://docker:8080/health - - export SERVICE_HOSTNAME="docker" && pytest tests/test_service.py -s - when: manual - - diff --git a/Dockerfile b/Dockerfile index 8ee0483..5f5700a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . .