Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ks6088ts committed Mar 17, 2024
1 parent 41e5760 commit 967a52a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.git
.github
.venv
*.pyc
*.env
.coverage
.devcontainer
.gitignore
.pre-commit-config.yaml
.pytest_cache
.ruff_cache
__pycache__
tests
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.11.8-slim-bookworm

ARG GIT_REVISION="0000000"
ARG GIT_TAG="x.x.x"

WORKDIR /app
# hadolint ignore=DL3008
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
make \
&& rm -rf /var/lib/apt/lists/*

# Install poetry: https://python-poetry.org/docs/#installing-with-the-official-installer
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sSL https://install.python-poetry.org | python3 -
ENV PATH="/root/.local/bin:$PATH"

# Install dependencies
COPY pyproject.toml poetry.lock Makefile /app/
RUN poetry config virtualenvs.create false && make install-deps
COPY . .

CMD ["python", "main.py"]
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Git
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git describe --tags --abbrev=0 | sed -e s/v//g)

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -30,3 +34,35 @@ test: ## run tests

.PHONY: ci-test
ci-test: install-deps-dev format-check lint test ## run CI tests

# ---
# Docker
# ---
DOCKER_REPO_NAME ?= ks6088ts
DOCKER_IMAGE_NAME ?= template-python
DOCKER_COMMAND ?= bash

.PHONY: docker-build
docker-build: ## build Docker image
docker build \
-t $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(GIT_TAG) \
--build-arg GIT_REVISION=$(GIT_REVISION) \
--build-arg GIT_TAG=$(GIT_TAG) \
.

.PHONY: docker-run
docker-run: ## run Docker container
docker run --rm -it $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(GIT_TAG) $(DOCKER_COMMAND)

.PHONY: docker-lint
docker-lint: ## lint Dockerfile
docker run --rm -i hadolint/hadolint < Dockerfile

.PHONY: docker-scan
docker-scan: ## scan Docker image
@# https://aquasecurity.github.io/trivy/v0.18.3/installation/#install-script
@which trivy || curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b $(TOOLS_DIR) v$(TRIVY_VERSION)
trivy image $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(GIT_TAG)

.PHONY: ci-test-docker
ci-test-docker: docker-lint docker-build docker-scan docker-run ## run CI test for Docker
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
def add_numbers(a, b):
return a + b


if __name__ == "__main__":
print(f"{add_numbers(3, 4)}")

0 comments on commit 967a52a

Please sign in to comment.