Skip to content

Commit

Permalink
Created docker
Browse files Browse the repository at this point in the history
  • Loading branch information
D0Nater committed Jul 11, 2024
1 parent dddfa2d commit b7c0ba0
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Docker

on:
pull_request:
push:
tags:
- v*
branches:
- main
- develop

permissions:
contents: read
packages: write

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Lowercase repository name
id: repo
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ steps.repo.outputs.lowercase }}
# generate Docker tags based on the following events/attributes
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
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=edge,branch=main
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
file: deployment/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Code lint

on:
push:
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
cache: "poetry"

- name: Install dependencies
run: poetry install

- name: Style check
run: |
poetry run black --check --diff .
poetry run isort --check --diff .
- name: Type check
run: |
poetry run mypy --install-types --non-interactive --show-error-codes --show-column-numbers --pretty .
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM python:3.12-slim@sha256:80571b64ab7b94950d49d413f074e1932b65f6f75e0c34747b40ea41889a2ca9 AS base

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean


# Export python requirements from poetry
FROM base AS poetry-export

ENV PATH=$PATH:/root/.local/bin POETRY_VERSION=1.8.3
RUN curl -sSL https://install.python-poetry.org | python -
COPY ./pyproject.toml ./pyproject.toml
COPY ./poetry.lock ./poetry.lock
RUN poetry export --no-interaction -o /requirements.txt --without-hashes --only main


# Install pip requirements
# This is needed to lower the size of the final image (no build dependencies)
FROM base AS requirements

# Install requirements
RUN apt-get update && apt-get install gcc python3-dev -y --no-install-recommends
COPY --from=poetry-export requirements.txt /requirements.txt
RUN pip install -r /requirements.txt


# Copy source code
# This is done in a separate stage to squash layers into one
FROM base AS source

RUN mkdir -p /app
WORKDIR /app
COPY deployment/entrypoint.sh /app/bin/
COPY pinger /app/pinger
COPY pyproject.toml /app
RUN chmod -R +x /app/bin
COPY README.md /app/README.md


# Remove apt files
FROM base AS pre-final

RUN rm -rf /var/lib/apt/lists/* \
&& apt-get clean


# Final image
FROM scratch AS final

LABEL org.opencontainers.image.source=https://github.com/D0Nater/PingerBot

COPY --from=pre-final / /

WORKDIR /app

ENV MODE=app

COPY --from=requirements /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=source /app /app
RUN pip install -e /app

CMD ["python", "-m", "pinger"]

0 comments on commit b7c0ba0

Please sign in to comment.