Skip to content

Commit

Permalink
Create docker image (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef authored Nov 10, 2022
1 parent 53e7286 commit a3ac472
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 3 deletions.
107 changes: 104 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ name: release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- "[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches:
- "master"

permissions:
contents: read
packages: write

jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -13,16 +21,109 @@ jobs:
id: setup-python
uses: actions/setup-python@v3
with:
python-version: '3.10'
python-version: "3.10"
- name: Install dependencies
run: |
pip install -U pip
pip install wheel
- name: Build package
run: python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@v1.5.0
if: github.event_name != 'pull_request'
uses: pypa/gh-action-pypi-publish@v1.5.1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true

docker:
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
python_version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: "0"

- name: Set output on new tags
if: github.event_name != 'pull_request'
run: echo "REMOTECV_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set output on PR
if: github.event_name == 'pull_request'
run: echo "REMOTECV_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Enable docker cache push
if: github.event_name != 'pull_request'
run: echo "CACHE_TO=type=registry,ref=ghcr.io/thumbor/remotecv:buildcache-${{ matrix.python_version }},mode=max" >> $GITHUB_ENV

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

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

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Quay.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
flavor: |
suffix=-py-${{ matrix.python_version }}
images: |
ghcr.io/thumbor/remotecv
quay.io/thumbor/remotecv
thumbororg/remotecv
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ./docker
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/thumbor/remotecv:buildcache-${{ matrix.python_version }}
cache-to: ${{ env.CACHE_TO }}
build-args: |
REMOTECV_VERSION=${{ env.REMOTECV_VERSION }}
PYTHON_VERSION=${{ matrix.python_version }}
41 changes: 41 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ARG PYTHON_VERSION
FROM python:${PYTHON_VERSION}-bullseye AS builder-image

ARG TARGETPLATFORM
ARG DEBIAN_FRONTEND=noninteractive
ARG REMOTECV_VERSION

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*


RUN python3 -m venv /home/remotecv/venv
ENV PATH="/home/remotecv/venv/bin:$PATH"

RUN pip3 install --no-cache-dir wheel && \
pip3 install --no-cache-dir remotecv==${REMOTECV_VERSION}

FROM python:${PYTHON_VERSION}-slim-bullseye AS runner-image

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN useradd --create-home remotecv
COPY --from=builder-image /home/remotecv/venv /home/remotecv/venv

USER remotecv

EXPOSE 8888

ENV PYTHONUNBUFFERED=1

ENV VIRTUAL_ENV=/home/remotecv/venv
ENV PATH="/home/remotecv/venv/bin:$PATH"

ENTRYPOINT ["remotecv"]

0 comments on commit a3ac472

Please sign in to comment.