Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tn fixes #2

Merged
merged 12 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions {{ cookiecutter.package_name|slugify }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ repos:
entry: flake8
language: system
types: [python]
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
- id: pydocstyle
name: pydocstyle
entry: pydocstyle
Expand All @@ -92,3 +87,8 @@ repos:
language: system
files: pyproject.toml
pass_filenames: false
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
3 changes: 2 additions & 1 deletion {{ cookiecutter.package_name|slugify }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ To add and install this package as a dependency of your project, run `poetry add

- This project follows the [Conventional Commits](https://www.conventionalcommits.org/) standard to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/) with [Commitizen](https://github.com/commitizen-tools/commitizen).
- Run `poe` from within the development environment to print a list of [Poe the Poet](https://github.com/nat-n/poethepoet) tasks available to run on this project.
- Run `poetry add {package}` from within the development environment to install a run time dependency and add it to `poetry.lock`. Add `--group dev` if you only need the package for local development, or `--group test` if you only need the package for linting or testing.
- Run `poetry add {package}` from within the development environment to install a run time dependency and add it to `pyproject.toml` and `poetry.lock`. Add `--group dev` if you only need the package for local development, or `--group test` if you only need the package for linting or testing.
- Run `poetry remove {package}` from within the development environment to uninstall a run time dependency and remove it from `pyproject.toml` and `poetry.lock`.
- Run `poetry update` from within the development environment to upgrade all dependencies to the latest versions allowed by `pyproject.toml`.
- Run `cz bump` to bump the package's version, update the `CHANGELOG.md`, and create a git tag.

Expand Down
6 changes: 5 additions & 1 deletion {{ cookiecutter.package_name|slugify }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ version_files = ["pyproject.toml:version"]
fastapi = "^0.70.1"
gunicorn = "^20.1.0"
{%- endif %}
{%- if cookiecutter.with_fastapi_api|int or cookiecutter.with_streamlit_app|int %}
poethepoet = "^0.12.2"
lsorber marked this conversation as resolved.
Show resolved Hide resolved
{%- endif %}
python = "^3.8.12"
{%- if cookiecutter.with_pydantic_typing|int %}
pydantic = "^1.9.0"
Expand Down Expand Up @@ -74,7 +77,9 @@ jupyterlab = "^3.2.5"
mypy = "^0.931"
pdoc = "^8.0.1"
pep8-naming = "^0.12.1"
{%- if not cookiecutter.with_fastapi_api|int and not cookiecutter.with_streamlit_app|int %}
poethepoet = "^0.12.2"
lsorber marked this conversation as resolved.
Show resolved Hide resolved
{%- endif %}
pre-commit = "^2.16.0"
pydocstyle = { extras = ["toml"], version = "^6.1.1" }
pytest = "^6.2.5"
Expand Down Expand Up @@ -268,7 +273,6 @@ testpaths = "tests"
cmd = """
streamlit run
--browser.gatherUsageStats false
--global.sharingMode off
lsorber marked this conversation as resolved.
Show resolved Hide resolved
--server.address 0.0.0.0
--server.port $port
--theme.base light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,44 @@ variables:
POETRY_HTTP_BASIC_{{ cookiecutter.private_package_repository_name|upper }}_PASSWORD: $CI_JOB_TOKEN
{%- endif %}
script:
- DOCKER_IMAGE_SHA=${DOCKER_IMAGE_SHA:-$(sha1sum Dockerfile poetry.lock pyproject.toml | sha1sum | cut -c 1-12)}
- DOCKER_IMAGE_SHA="${DOCKER_IMAGE_SHA:-$(sha1sum Dockerfile poetry.lock pyproject.toml | sha1sum | cut -c 1-12)}"
- echo "CI_IMAGE_SHA=$DOCKER_IMAGE_SHA" >> .env
- |
echo -n $DOCKER_REGISTRY_PASSWORD | docker login --username $DOCKER_REGISTRY_USER --password-stdin $DOCKER_REGISTRY
DOCKER_PUSH=${DOCKER_PUSH:-$(timeout 2s docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_SHA >/dev/null 2>1 && echo $? || echo $?)}
if [ $DOCKER_PUSH -ne 1 ]; then
echo "$DOCKER_REGISTRY_PASSWORD" | docker login --username "$DOCKER_REGISTRY_USER" --password-stdin "$DOCKER_REGISTRY"
DOCKER_PUSH=${DOCKER_PUSH:-$(timeout 2s docker pull "$DOCKER_IMAGE":"$DOCKER_IMAGE_SHA" >/dev/null 2>&1 && echo $? || echo $?)}
if [ "$DOCKER_PUSH" -ne 1 ]; then
echo "$DOCKER_IMAGE:$DOCKER_IMAGE_SHA exists, skipping this job..."
else
# Compile a list of image tags consisting of a hash of its contents, the latest tag if this
# pipeline is running for the default branch, and the Git tag if this commit is tagged.
DOCKER_TAGS=( "$DOCKER_IMAGE_SHA" )
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then DOCKER_TAGS+=( "latest" ); fi
if [[ -n $CI_COMMIT_TAG ]]; then DOCKER_TAGS+=( "$CI_COMMIT_TAG" ); fi
if [[ -n $CI_ENVIRONMENT_NAME ]]; then DOCKER_TAGS+=( "$CI_ENVIRONMENT_NAME" ); fi
DOCKER_TAGS="$DOCKER_IMAGE_SHA"
if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then DOCKER_TAGS="$DOCKER_TAGS latest"; fi
if [ -n "$CI_COMMIT_TAG" ]; then DOCKER_TAGS="$DOCKER_TAGS $CI_COMMIT_TAG"; fi
if [ -n "$CI_ENVIRONMENT_NAME" ]; then DOCKER_TAGS="$DOCKER_TAGS $CI_ENVIRONMENT_NAME"; fi
DOCKER_TAGS_JOINED=""
for DOCKER_TAG in "$DOCKER_TAGS"; do
DOCKER_TAGS_JOINED="$DOCKER_TAGS_JOINED --tag $DOCKER_IMAGE:$DOCKER_TAG"
done

# Build the Docker image with all of the selected tags.
DOCKER_TAGS_JOINED=${DOCKER_TAGS[@]}
DOCKER_TAGS_JOINED="--tag $DOCKER_IMAGE:${DOCKER_TAGS_JOINED// / --tag $DOCKER_IMAGE:}"
DOCKER_BUILDKIT=1 docker build \
{%- if cookiecutter.with_fastapi_api|int or cookiecutter.with_streamlit_app|int %}
--build-arg APP_BASE_IMAGE=${DOCKER_BASE_IMAGE:-ci} \
--build-arg APP_BASE_IMAGE="${DOCKER_BASE_IMAGE:-ci}" \
{%- endif %}
--build-arg SOURCE_BRANCH=$CI_COMMIT_REF_NAME \
--build-arg SOURCE_COMMIT=$CI_COMMIT_SHA \
--build-arg SOURCE_TIMESTAMP=$CI_COMMIT_TIMESTAMP \
--build-arg SOURCE_BRANCH="$CI_COMMIT_REF_NAME" \
--build-arg SOURCE_COMMIT="$CI_COMMIT_SHA" \
--build-arg SOURCE_TIMESTAMP="$CI_COMMIT_TIMESTAMP" \
{%- if cookiecutter.private_package_repository_name %}
--secret id=poetry-http-basic-username,env=POETRY_HTTP_BASIC_{{ cookiecutter.private_package_repository_name|upper }}_USERNAME \
--secret id=poetry-http-basic-password,env=POETRY_HTTP_BASIC_{{ cookiecutter.private_package_repository_name|upper }}_PASSWORD \
{%- endif %}
--target $DOCKER_TARGET \
--target "$DOCKER_TARGET" \
--pull \
$DOCKER_TAGS_JOINED \
.

# Push all the tagged images.
for DOCKER_TAG in ${DOCKER_TAGS[@]}; do
for DOCKER_TAG in "$DOCKER_TAGS"; do
docker push "$DOCKER_IMAGE:$DOCKER_TAG"
done
fi
Expand Down