Skip to content

Commit 943b189

Browse files
authored
feat: docker packaging (#15)
1 parent 5f00d27 commit 943b189

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

.github/workflows/docker.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push-image:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
22+
- name: Log in to the Container registry
23+
uses: docker/[email protected]
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/[email protected]
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
35+
- name: Build and push Docker image
36+
uses: docker/[email protected]
37+
with:
38+
context: .
39+
push: true
40+
tags: ${{ steps.meta.outputs.tags }}
41+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# syntax = docker/dockerfile:1.3
2+
ARG PYTHON_BUILD_IMAGE=python:3.10.0-bullseye
3+
ARG PYTHON_DIST_IMAGE=python:3.10.0-slim-bullseye
4+
5+
# Build Container
6+
FROM $PYTHON_BUILD_IMAGE as build
7+
8+
RUN adduser --disabled-login --gecos "" tfdevops
9+
10+
RUN python3 -m venv /app && chown -R tfdevops: /app
11+
USER tfdevops
12+
13+
ENV POETRY_VERSION=1.1.11 \
14+
VIRTUAL_ENV="/app" \
15+
PATH="/home/tfdevops/.local/bin:/app/bin:${PATH}"
16+
17+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python3 -
18+
19+
COPY pyproject.toml poetry.lock /app
20+
WORKDIR /app
21+
22+
RUN --mount=type=cache,target=/home/tfdevops/.cache,uid=1000 poetry install --no-root --no-dev
23+
24+
ADD . /app
25+
RUN --mount=type=cache,target=/home/tfdevops/.cache,uid=1000 poetry install --no-dev
26+
27+
FROM $PYTHON_DIST_IMAGE
28+
29+
ENV PYTHONFAULTHANDLER=1 \
30+
PYTHONUNBUFFERED=1 \
31+
PYTHONHASHSEED=random \
32+
AWS_RETRY_MODE=adaptive \
33+
AWS_STS_REGIONAL_ENDPOINTS=regional \
34+
AWS_MAX_ATTEMPTS=6 \
35+
LC_ALL="C.UTF-8" LANG="C.UTF-8"
36+
37+
COPY --from=build /etc/passwd /etc/passwd
38+
COPY --from=build /etc/group /etc/group
39+
COPY --chown=tfdevops:tfdevops --from=build /app /app
40+
41+
USER tfdevops
42+
WORKDIR /app
43+
ENTRYPOINT ["/app/bin/tfdevops"]
44+
CMD ["--help"]

justfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ lint:
55

66
test:
77
pytest -v tests/unit
8+
9+
image:
10+
DOCKER_BUILDKIT=1 docker buildx build \
11+
--label "org.opencontainers.image.vendor=stacklet" \
12+
--label "org.opencontainers.image.source=https://github.com/stacklet/tfdevops" \
13+
--label "org.opencontainers.image.licenses=Apache-2.0" \
14+
--label "org.opencontainers.image.title=Terraform Devops Guru" \
15+
-t "tfdevops:latest" \
16+
--progress plain \
17+
--load .

0 commit comments

Comments
 (0)