Skip to content

Commit

Permalink
Merge pull request #108 from danielfromearth/feature/issue-96-contain…
Browse files Browse the repository at this point in the history
…er-registry

Feature/issue 96 container registry
  • Loading branch information
danielfromearth authored Mar 1, 2024
2 parents f02755d + 4b07b19 commit 6677b37
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 11 deletions.
56 changes: 52 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
POETRY_VERSION: "1.3.2"
PYTHON_VERSION: "3.10"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
run_tests:
uses: ./.github/workflows/run_tests.yml
Expand All @@ -24,12 +30,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
uses: abatilo/actions-poetry@v3.0.0
with:
poetry-version: 1.3.2
poetry-version: ${{ env.POETRY_VERSION }}

- name: Get version
id: get-version
Expand Down Expand Up @@ -78,11 +84,11 @@ jobs:
CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }}
# True if the version already has a 'rc' pre-release identifier
BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }}
# True if the version already has a 'alpha' pre-release identifier
# True if the version already has an 'alpha' pre-release identifier
BUMP_A: ${{ contains(steps.get-version.outputs.current_version, 'a') }}
# True if the version already has a 'beta' pre-release identifier
BUMP_B: ${{ contains(steps.get-version.outputs.current_version, 'b') }}
# Remove rc* from end of version string
# Remove rc* from the end of version string
# The ${string%%substring} syntax below deletes the longest match of $substring from back of $string.
run: |
if [ "$BUMP_RC" = true ]; then
Expand All @@ -95,6 +101,48 @@ jobs:
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
echo "venue=ops" >> $GITHUB_ENV
- name: Log in to the Container registry
# TODO: change this and subsequent docker steps back to NOT (as follows), after testing in the feature branch --- if: ${{ !startsWith(github.ref, 'refs/heads/feature') }}
if: ${{ startsWith(github.ref, 'refs/heads/feature/') }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
# if: ${{ !startsWith(github.ref, 'refs/heads/feature') }}
if: ${{ startsWith(github.ref, 'refs/heads/feature/') }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,pattern={{version}},value=${{ env.software_version }}
type=raw,value=${{ env.venue }}
# - name: Wait for package
## if: ${{ !startsWith(github.ref, 'refs/heads/feature') }}
# if: ${{ startsWith(github.ref, 'refs/heads/feature/') }}
# run: |
# pip install tenacity
# ${GITHUB_WORKSPACE}/.github/workflows/wait-for-pypi.py ${{env.pyproject_name}}[harmony]==${{ env.software_version }}

- name: Build and push Docker image
# if: ${{ !startsWith(github.ref, 'refs/heads/feature') }}
if: ${{ startsWith(github.ref, 'refs/heads/feature/') }}
id: docker-push
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
build-args: |
SOURCE=${{env.pyproject_name}}[harmony]==${{ env.software_version }}
push: true
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# - name: Commit Version Bump
# # If building develop, a release branch, or main then we commit the version bump back to the repo
# if: |
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
workflow_call:
workflow_dispatch:

env:
POETRY_VERSION: "1.3.2"
PYTHON_VERSION: "3.10"

jobs:
build_and_test:
runs-on: ubuntu-latest
Expand All @@ -20,12 +24,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: ${{ env.PYTHON_VERSION }}

- name: Set up Poetry
uses: abatilo/actions-poetry@v3.0.0
with:
poetry-version: 1.3.2
poetry-version: ${{ env.POETRY_VERSION }}

- name: Install package
run: poetry install
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/wait-for-pypi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
import logging
import subprocess
import sys
import tempfile

import tenacity

"""
Sometimes the package published to PyPi is not immediately available for download from the index.
This script simply repeatedly tries to download a specific version of a package
from PyPI (or test.pypi) until it succeeds or a limit is exceeded.
"""


@tenacity.retry(
wait=tenacity.wait_exponential(multiplier=1, min=4, max=10),
retry=tenacity.retry_if_exception_type(subprocess.CalledProcessError),
stop=tenacity.stop_after_delay(120),
before_sleep=tenacity.before_sleep_log(logging.getLogger(__name__), logging.DEBUG),
)
def download_package(package):
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"--isolated",
"--no-cache-dir",
"download",
"--no-deps",
"-d",
tempfile.gettempdir(),
"--index-url",
"https://pypi.org/simple/",
"--extra-index-url",
"https://test.pypi.org/simple/",
package,
]
)


if __name__ == "__main__":
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
package_spec = sys.argv[1]
download_package(package_spec)
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: tests(/\w*)*/functional/t/trailing_whitespaces.py|tests/pyreverse/data/.*.html|doc/data/messages/t/trailing-whitespace/bad.py
Expand All @@ -15,25 +15,25 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.290'
rev: 'v0.2.2'
hooks:
- id: ruff
args: [ "--fix" ]

# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 24.2.0
hooks:
- id: black-jupyter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.8.0
hooks:
- id: mypy

# Other Linters
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
rev: v1.35.1
hooks:
- id: yamllint
args: ["-d {extends: relaxed, rules: {line-length: {max: 120}}}"]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Issue #8](https://github.com/danielfromearth/stitchee/issues/8): Create working Docker image
- [Issue #10](https://github.com/danielfromearth/stitchee/issues/10): Add code necessary to communicate with Harmony
- [Issue #49](https://github.com/danielfromearth/stitchee/issues/49): More CLI arguments for finer control of concatenation method
- [PR #99](https://github.com/danielfromearth/stitchee/pull/99): Add Docker build steps to GitHub Actions workflow
### Changed
- [PR #12](https://github.com/danielfromearth/stitchee/pull/12): Changed name to "stitchee"
- [PR #15](https://github.com/danielfromearth/stitchee/pull/15): Use ruff+black chain for pre-commit lint & format
Expand Down

0 comments on commit 6677b37

Please sign in to comment.