diff --git a/.github/workflows/image-publish.yml b/.github/workflows/image-publish.yml new file mode 100644 index 0000000..1ac7bfd --- /dev/null +++ b/.github/workflows/image-publish.yml @@ -0,0 +1,48 @@ +name: docker release + + +on: + push: + branches-ignore: + - '**' + tags: + - '**' + workflow_dispatch: + + +env: + DOCKER_IMAGE_NAME: ghcr.io/wipacrepo/wipac-dev-py-dependencies-action + + +jobs: + + docker: + name: "Docker Image" + runs-on: ubuntu-latest + steps: + - name: Checkout Project + uses: actions/checkout@v4 + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.DOCKER_IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} diff --git a/README.md b/README.md index d3e2cd0..9be69f9 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,25 @@ # wipac-dev-py-dependencies-action -GitHub Action Package for Automating Python-Package Dependency Management +GitHub Action Package for Automating Python-Package Dependency Management ## Overview -This GitHub Action creates 1+ `dependencies*.log`-type file(s) for documenting dependency versions (ex: `dependencies.log`, `dependencies-dev.log`, `dependencies-from-Dockerfile.log`, etc.). These files are similar to `requirements*.txt`-type files, with the distinct difference that `dependencies*.log`-type files are not intended to be the source of truth, but rather, a reflection of the tested environment(s). If dependency-version pinning is wanted, it should be done by the user in the `setup.cfg`/`pyproject.toml` file. + +This GitHub Action creates 1+ `dependencies*.log` file(s) for documenting dependency versions (ex: `dependencies.log`, `dependencies-dev.log`, `dependencies-docker-default.log`, etc.). These files are similar to `requirements*.txt`-type files, with the distinct difference that *`dependencies*.log`-type files are a reflection of the built environment(s).* If dependency-version pinning is wanted, it should be done by the user in the `setup.cfg`/`pyproject.toml` file. ### Details -The root directory's `dependencies.log` is overwritten/updated (by way of `pip freeze` + [`pipdeptree`](https://pypi.org/project/pipdeptree/)) along with dedicated `dependencies-EXTRA.log` files for each package "extra". -_However,_ if there is a `Dockerfile` present at the root of the target repo, a similar process occurs but _within_ a container built from the `Dockerfile`. This log file is named `dependencies-from-Dockerfile.log`. If there are other `Dockerfile`s present (ex: `Dockerfile-foo`), additional files are generated using the appropriate name (ex: `dependencies-from-Dockerfile-foo.log`). +This action uses `pip freeze` + [`pipdeptree`](https://pypi.org/project/pipdeptree/) to generate the `dependencies*.log` file(s). All current `dependencies*.log` files are deleted/overwritten/updated. By default, these file(s) are placed at the client repository's root. Setting the input arg `use_directory: true` will place the generated file(s) in `dependencies-logs/`. + +#### Generating from Python Package + +By default, this action generates a `dependencies*.log` file using the environment built from the client's Python package. In addition, a dedicated `dependencies-EXTRA.log` file is generated for each package "extra". + +#### Generating from Docker Images + +If the user supplies Docker image(s) tagged with `"py-dep-this"` (configurable by the input arg, `docker_tag_to_dep`). `dependencies*.log` file(s), named `dependencies-docker-{IMAGE_NAME}.log`, are generated from within each container. ### Example File + ``` # # This file was autogenerated by WIPACrepo/wipac-dev-py-setup-action @@ -43,4 +52,5 @@ _However,_ if there is a `Dockerfile` present at the root of the target repo, a ``` ### Full CI-Workflow: Using Alongside Other GitHub Actions + See https://github.com/WIPACrepo/wipac-dev-py-setup-action#full-ci-workflow-using-alongside-other-github-actions diff --git a/action.sh b/action.sh new file mode 100755 index 0000000..606591d --- /dev/null +++ b/action.sh @@ -0,0 +1,67 @@ +#!/bin/bash +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex + +ls $REPO_PATH + +# env vars +export PACKAGE_NAME=$(python3 $GITHUB_ACTION_PATH/utils/get_package_name.py .) + + +# grab local copy to avoid path mangling -- replace when https://github.com/WIPACrepo/wipac-dev-py-dependencies-action/issues/6 +pip install requests semantic-version +temp_dir=$(mktemp -d) && cd $temp_dir && trap 'rm -rf $temp_dir' EXIT +wget https://raw.githubusercontent.com/WIPACrepo/wipac-dev-tools/main/wipac_dev_tools/semver_parser_tools.py -O $temp_dir/semver_parser_tools_local.py + +# get python3 version (max) -- copied from https://github.com/WIPACrepo/wipac-dev-py-versions-action/blob/main/action.yml +export PACKAGE_MAX_PYTHON_VERSION=$(python -c ' +import os, re +import semver_parser_tools_local as semver_parser_tools + +repo_path = os.environ["REPO_PATH"] + +semver_range = "" +if os.path.isfile(f"{repo_path}/pyproject.toml"): + # ex: requires-python = ">=3.8, <3.13" + pat = re.compile(r"requires-python = \"(?P[^\"]+)\"$") + with open(f"{repo_path}/pyproject.toml") as f: + for line in f: + if m := pat.match(line): + semver_range = m.group("semver_range") + if not semver_range: + raise Exception("could not find `requires-python` entry in pyproject.toml") +elif os.path.isfile(f"{repo_path}/setup.cfg"): + # ex: python_requires = >=3.8, <3.13 + pat = re.compile(r"python_requires = (?P.+)$") + with open(f"{repo_path}/setup.cfg") as f: + for line in f: + if m := pat.match(line): + semver_range = m.group("semver_range") + if not semver_range: + raise Exception("could not find `python_requires` entry in setup.cfg") +else: + raise Exception("could not find pyproject.toml nor setup.cfg") + +top_python = semver_parser_tools.get_latest_py3_release() +all_matches = semver_parser_tools.list_all_majmin_versions( + major=top_python[0], + semver_range=semver_range, + max_minor=top_python[1], +) +print(f"{max(all_matches)[0]}.{max(all_matches)[1]}") +') + +echo $PACKAGE_MAX_PYTHON_VERSION + + +# Build +if [ -f $REPO_PATH/Dockerfile ]; then + # from Dockerfile(s)... + $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-from-user-docker-images.sh +else + # from setup.cfg... + $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-from-repo-python-pkg.sh +fi + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/action.yml b/action.yml index ec55ebe..63eea05 100644 --- a/action.yml +++ b/action.yml @@ -10,10 +10,15 @@ inputs: description: 'The email used for "git config user.email"' required: false default: github-actions@github.com - dockerfile_nametags: - description: 'A space-separated list of image names and tags to apply to each Dockerfile for locally dependent builds (these images are built first), ex: Dockerfile:icecube/skymap_scanner:latest Dockerfile_pulsar:icecube/skymap_scanner:latest_pulsar' + docker_tag_to_dep: + description: 'The email used for "git config user.email"' + required: false + default: py-dep-this + use_directory: + description: 'Whether to put all generated dep-log files, relative to the project/repo directory; (true/false)' required: false - default: '' + default: "false" + # outputs: # random-number: @@ -29,6 +34,8 @@ runs: - name: Is this the most recent commit? It won't be if the action was reran run: | + # check git status + echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" git fetch &> /dev/null if [[ $(git status -sb | grep behind) ]]; then echo "IS_GIT_BEHIND=true" >> $GITHUB_ENV @@ -39,6 +46,8 @@ runs: - name: Git config if: env.IS_GIT_BEHIND != 'true' run: | + # git config + echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" git config user.name ${{ inputs.git_committer_name }} git config user.email ${{ inputs.git_committer_email }} shell: bash @@ -52,9 +61,15 @@ runs: - name: Build dependencies.log (and commit) if: env.IS_GIT_BEHIND != 'true' + env: + ACTION_REPOSITORY: ${{ github.action_repository }} # https://github.com/github/docs/issues/25336#issuecomment-1736251764 + GITHUB_ACTION_PATH: ${{ github.action_path }} + DOCKER_TAG_TO_DEP: ${{ inputs.docker_tag_to_dep }} + DEST_DIRECTORY_IF_WANTED: dependencies-logs/ run: | - set -x # turn on debugging - + # build dependencies.log (and commit) + set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x + # append permissive line to .gitignore since *.log is commonly present line='!dependencies*.log' if [[ ! $(grep -F "$line" .gitignore) ]]; then @@ -66,75 +81,33 @@ runs: git commit -m " update .gitignore" || true # okay if no change tail .gitignore fi - + + set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x + # remove any old ones, then regenerate only what's needed - rm dependencies*.log || true - - export PACKAGE_NAME=$(python3 ${{ github.action_path }}/utils/get_package_name.py .) - export GITHUB_ACTION_PATH=${{ github.action_path }} - export ACTION_REPOSITORY="WIPACrepo/wipac-dev-py-setup-action" - - # grab local copy to avoid path mangling -- replace when https://github.com/WIPACrepo/wipac-dev-py-dependencies-action/issues/6 - pip install requests semantic-version - wget https://raw.githubusercontent.com/WIPACrepo/wipac-dev-tools/main/wipac_dev_tools/semver_parser_tools.py -O semver_parser_tools_local.py + (find . -name "dependencies*.log" -type f -print0 | xargs -0 rm) || true - # get python3 version (max) -- copied from https://github.com/WIPACrepo/wipac-dev-py-versions-action/blob/main/action.yml - export PACKAGE_MAX_PYTHON_VERSION=$(python -c ' - import os, re - import semver_parser_tools_local as semver_parser_tools + # run script + export REPO_PATH=$(pwd) + /bin/bash $GITHUB_ACTION_PATH/action.sh - semver_range = "" - if os.path.isfile("pyproject.toml"): - # ex: requires-python = ">=3.8, <3.13" - pat = re.compile(r"requires-python = \"(?P[^\"]+)\"$") - with open("pyproject.toml") as f: - for line in f: - if m := pat.match(line): - semver_range = m.group("semver_range") - if not semver_range: - raise Exception("could not find `requires-python` entry in pyproject.toml") - elif os.path.isfile("setup.cfg"): - # ex: python_requires = >=3.8, <3.13 - pat = re.compile(r"python_requires = (?P.+)$") - with open("setup.cfg") as f: - for line in f: - if m := pat.match(line): - semver_range = m.group("semver_range") - if not semver_range: - raise Exception("could not find `python_requires` entry in setup.cfg") - else: - raise Exception("could not find pyproject.toml nor setup.cfg") + set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x - top_python = semver_parser_tools.get_latest_py3_release() - all_matches = semver_parser_tools.list_all_majmin_versions( - major=top_python[0], - semver_range=semver_range, - max_minor=top_python[1], - ) - print(f"{max(all_matches)[0]}.{max(all_matches)[1]}") - ') - echo $PACKAGE_MAX_PYTHON_VERSION - - # Build - if [ -f ./Dockerfile ]; then - # from Dockerfile(s)... - export DOCKERFILE_NAMETAGS=${{ inputs.dockerfile_nametags }} - ${{ github.action_path }}/generate_dep_logs/gen-deps-from-repo-dockerfiles.sh - else - # from setup.cfg... - ${{ github.action_path }}/generate_dep_logs/gen-deps-from-repo-python-pkg.sh + if [[ $( echo "${{ inputs.use_directory }}" | awk '{print tolower($0)}' ) == "true" ]]; then + mkdir -p $DEST_DIRECTORY_IF_WANTED + find . -name "dependencies*.log" -type f -exec mv -i {} $DEST_DIRECTORY_IF_WANTED \; fi - + # Commit - rm semver_parser_tools_local.py git add . git commit -m " update dependencies*.log files(s)" || true # okay if no change - shell: bash - name: Push changes if: env.IS_GIT_BEHIND != 'true' run: | + # push changes (if needed) + echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" status=`git status 2>&1 | tee` ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"` if [ "$ahead" -eq "1" ]; then diff --git a/generate_dep_logs/gen-deps-from-repo-dockerfiles.sh b/generate_dep_logs/gen-deps-from-repo-dockerfiles.sh deleted file mode 100755 index f569be4..0000000 --- a/generate_dep_logs/gen-deps-from-repo-dockerfiles.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -set -x # turn on debugging -set -e - -######################################################################## -# -# Generate dependencies-*.log for each Dockerfile* -# -######################################################################## - - -# install podman if needed... (grep -o -> 1 if found) -if [[ $(grep -o "USER" ./Dockerfile) ]]; then - podman --version - # 'uid' & 'gid' were added in https://github.com/containers/podman/releases/tag/v4.3.0 - $GITHUB_ACTION_PATH/utils/install-podman.sh - podman --version - USE_PODMAN='--podman' -fi - - -# 1st - the dockerfiles in $DOCKERFILE_NAMETAGS -for fname_nametag in $DOCKERFILE_NAMETAGS; do - echo $fname_nametag - docker images - fname=$(echo $fname_nametag | cut -d ':' -f1) - nametag=$(echo $fname_nametag | cut -d ':' -f2-) - $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps.sh \ - $fname \ - "dependencies-from-$(basename $fname).log" \ - "within the container built from '$fname'" \ - $nametag \ - $USE_PODMAN -done -# 2nd - the rest of the dockerfiles -for fname in ./Dockerfile*; do - if [[ $DOCKERFILE_NAMETAGS == *$(basename $fname):* ]]; then - continue - fi - echo $fname - docker images - $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps.sh \ - $fname \ - "dependencies-from-$(basename $fname).log" \ - "within the container built from '$fname'" \ - $USE_PODMAN -done \ No newline at end of file diff --git a/generate_dep_logs/gen-deps-from-repo-python-pkg.sh b/generate_dep_logs/gen-deps-from-repo-python-pkg.sh index 06eb9a9..7cea354 100755 --- a/generate_dep_logs/gen-deps-from-repo-python-pkg.sh +++ b/generate_dep_logs/gen-deps-from-repo-python-pkg.sh @@ -1,6 +1,7 @@ #!/bin/bash -set -x # turn on debugging -set -e +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex ######################################################################## # @@ -9,14 +10,14 @@ set -e # ######################################################################## +ls $REPO_PATH # get all extras -VARIANTS_LIST=$(python3 $GITHUB_ACTION_PATH/utils/list_extras.py .) +VARIANTS_LIST=$(python3 $GITHUB_ACTION_PATH/utils/list_extras.py $REPO_PATH) VARIANTS_LIST="- $(echo $VARIANTS_LIST)" # "-" signifies regular package echo $VARIANTS_LIST -TEMPDIR=$(mktemp -d) -trap 'rm -rf "$TEMPDIR"' EXIT +TEMPDIR=$(mktemp -d) && trap 'rm -rf "$TEMPDIR"' EXIT # generate dependencies-*.log for each extras_require (each in a subproc) for variant in $VARIANTS_LIST; do @@ -25,13 +26,14 @@ for variant in $VARIANTS_LIST; do if [[ $variant == "-" ]]; then # regular package (not an extra) pip_install_pkg="." dockerfile="$TEMPDIR/Dockerfile" - DEPS_LOG_FILE="dependencies.log" + DEPS_LOG_FNAME="dependencies.log" else pip_install_pkg=".[$variant]" dockerfile="$TEMPDIR/Dockerfile_$variant" - DEPS_LOG_FILE="dependencies-${variant}.log" + DEPS_LOG_FNAME="dependencies-${variant}.log" fi + # make an ad-hoc dockerfile cat << EOF >> $dockerfile FROM python:$PACKAGE_MAX_PYTHON_VERSION COPY . . @@ -39,16 +41,24 @@ RUN pip install --no-cache-dir $pip_install_pkg CMD [] EOF - $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps.sh \ - $(realpath $dockerfile) \ - $DEPS_LOG_FILE \ + # and build it + image="gen-$( basename $DEPS_LOG_FNAME ):local" + docker build -t $image --file $dockerfile $REPO_PATH + + # generate deps! + $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-within-container.sh \ + $image \ + $REPO_PATH/$DEPS_LOG_FNAME \ "from \`pip install $pip_install_pkg\`" \ & done + echo # wait for all subprocs for _ in $VARIANTS_LIST; do wait -n done + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/generate_dep_logs/gen-deps-from-user-docker-images.sh b/generate_dep_logs/gen-deps-from-user-docker-images.sh new file mode 100755 index 0000000..d0bf74f --- /dev/null +++ b/generate_dep_logs/gen-deps-from-user-docker-images.sh @@ -0,0 +1,44 @@ +#!/bin/bash +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex + +######################################################################## +# +# Generate dependencies-*.log for each user-supplied image +# +######################################################################## + +ls $REPO_PATH + +# install podman if needed... (grep -o -> 1 if found) +if [[ $(grep -o "USER" $REPO_PATH/Dockerfile) ]]; then + podman --version + # 'uid' & 'gid' were added in https://github.com/containers/podman/releases/tag/v4.3.0 + $GITHUB_ACTION_PATH/utils/install-podman.sh + podman --version + USE_PODMAN='--podman' +fi + +# get images to dep +images_to_dep=$(docker images | awk -v pat="$DOCKER_TAG_TO_DEP" '$2==pat' | awk -F ' ' '{print $1":"$2}') + +# compare counts of dockerfiles vs images, yes not perfect (considering build args) but moderately effective +n_images=$( echo "$images_to_dep" | wc -l ) +n_dockerfiles=$( find $REPO_PATH -name "Dockerfile*" -printf '.' | wc -m ) +if (( n_dockerfiles > n_images )); then + echo "ERROR: $n_dockerfiles 'Dockerfile*' files found but $n_images pre-built Docker images (with tag='$DOCKER_TAG_TO_DEP') were provided" + exit 1 +fi + +# dep each image +for image in $images_to_dep; do + echo $image + $GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-within-container.sh \ + $image \ + "$REPO_PATH/dependencies-docker-$( echo $image | cut -d ":" -f 1 | tr '/' '-' ).log" \ + "within a container using the user-supplied image '$( echo $image | cut -d ":" -f 1 )'" \ + $USE_PODMAN +done + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/generate_dep_logs/gen-deps-within-container.sh b/generate_dep_logs/gen-deps-within-container.sh new file mode 100755 index 0000000..af5700d --- /dev/null +++ b/generate_dep_logs/gen-deps-within-container.sh @@ -0,0 +1,68 @@ +#!/bin/bash +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex + +######################################################################## +# +# Generate dependencies-log file for the given docker image +# +######################################################################## + +ls $REPO_PATH + +######################################################################## + +# GET ARGS +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "Usage: gen-deps-within-container.sh DOCKER_IMAGE DEPS_LOG_FILE SUBTITLE [--podman]" + exit 1 +else + DOCKER_IMAGE="$1" + DEPS_LOG_FILE="$2" + SUBTITLE="$3" +fi + +# VALIDATE ARGS +if [ -z "$(docker images -q $DOCKER_IMAGE 2> /dev/null)" ]; then + echo "ERROR: image not found: $DOCKER_IMAGE" + exit 2 +fi + +######################################################################## + +# move script +TEMPDIR=$(mktemp -d) && trap 'rm -rf "$TEMPDIR"' EXIT +cp $GITHUB_ACTION_PATH/generate_dep_logs/pip-freeze-tree.sh $TEMPDIR +chmod +x $TEMPDIR/pip-freeze-tree.sh + + +# build & generate +if [[ $* == *--podman* ]]; then # look for flag anywhere in args + podman pull docker-daemon:$DOCKER_IMAGE + podman images + # 'uid' & 'gid' were added in https://github.com/containers/podman/releases/tag/v4.3.0 + podman run --rm -i \ + --env PACKAGE_NAME=$PACKAGE_NAME \ + --env ACTION_REPOSITORY=$ACTION_REPOSITORY \ + --env SUBTITLE="$SUBTITLE" \ + --mount type=bind,source=$(realpath $TEMPDIR/),target=/local/$TEMPDIR \ + --userns=keep-id:uid=1000,gid=1000 \ + $DOCKER_IMAGE \ + /local/$TEMPDIR/pip-freeze-tree.sh /local/$TEMPDIR/deps.log +else + docker run --rm -i \ + --env PACKAGE_NAME=$PACKAGE_NAME \ + --env ACTION_REPOSITORY=$ACTION_REPOSITORY \ + --env SUBTITLE="$SUBTITLE" \ + --mount type=bind,source=$(realpath $TEMPDIR/),target=/local/$TEMPDIR \ + $DOCKER_IMAGE \ + /local/$TEMPDIR/pip-freeze-tree.sh /local/$TEMPDIR/deps.log +fi + +ls $TEMPDIR + +# finally, move/overwrite the dep-log file that was generated above +mv $TEMPDIR/deps.log $DEPS_LOG_FILE + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/generate_dep_logs/gen-deps.sh b/generate_dep_logs/gen-deps.sh deleted file mode 100755 index 3149893..0000000 --- a/generate_dep_logs/gen-deps.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -set -x # turn on debugging -set -e - -######################################################################## -# -# Generate dependencies-dockerfile*.log for given Dockerfile -# -######################################################################## - -if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "Usage: gen-deps.sh DOCKERFILE DEPS_LOG_FILE SUBTITLE [IMAGE_NAMETAG] [--podman]" - exit 1 -fi -if [ ! -f "$1" ]; then - echo "File Not Found: $1" - exit 2 -fi -DEPS_LOG_FILE="$2" -SUBTITLE="$3" -if [ -z "$4" ] || [[ "$4" == --* ]]; then # optional -> get default (& not a flag) - # lower basename without extension - image="for-deps-$(echo $(basename ${DEPS_LOG_FILE%.*}) | awk '{print tolower($0)}')" -else - image="$4" -fi - - -# move script -TEMPDIR=$(mktemp -d) -trap 'rm -rf "$TEMPDIR"' EXIT -cp $GITHUB_ACTION_PATH/generate_dep_logs/pip-freeze-tree.sh $TEMPDIR -chmod +x $TEMPDIR/pip-freeze-tree.sh - - -# build & generate -if [[ $* == *--podman* ]]; then # look for flag anywhere in args - podman build -t $image --file $1 . - # 'uid' & 'gid' were added in https://github.com/containers/podman/releases/tag/v4.3.0 - podman run --rm -i \ - --env PACKAGE_NAME=$PACKAGE_NAME \ - --env ACTION_REPOSITORY=$ACTION_REPOSITORY \ - --env SUBTITLE="$SUBTITLE" \ - --mount type=bind,source=$(realpath $TEMPDIR/),target=/local/$TEMPDIR \ - --userns=keep-id:uid=1000,gid=1000 \ - $image \ - /local/$TEMPDIR/pip-freeze-tree.sh /local/$TEMPDIR/$DEPS_LOG_FILE -else - docker build -t $image --file $1 . - docker run --rm -i \ - --env PACKAGE_NAME=$PACKAGE_NAME \ - --env ACTION_REPOSITORY=$ACTION_REPOSITORY \ - --env SUBTITLE="$SUBTITLE" \ - --mount type=bind,source=$(realpath $TEMPDIR/),target=/local/$TEMPDIR \ - $image \ - /local/$TEMPDIR/pip-freeze-tree.sh /local/$TEMPDIR/$DEPS_LOG_FILE -fi - -ls $TEMPDIR -mv $TEMPDIR/$DEPS_LOG_FILE $DEPS_LOG_FILE diff --git a/generate_dep_logs/pip-freeze-tree.sh b/generate_dep_logs/pip-freeze-tree.sh index 319773a..d6031fe 100755 --- a/generate_dep_logs/pip-freeze-tree.sh +++ b/generate_dep_logs/pip-freeze-tree.sh @@ -1,6 +1,7 @@ #!/bin/bash -set -x # turn on debugging -set -e +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex ######################################################################## # @@ -65,3 +66,5 @@ $(cat $pip_dep_tree) EOF cat $deps_file + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/utils/install-podman.sh b/utils/install-podman.sh index 87cd893..f12dc66 100755 --- a/utils/install-podman.sh +++ b/utils/install-podman.sh @@ -1,6 +1,7 @@ #!/bin/bash -set -x # turn on debugging -set -e +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "$( basename "$0" )..." && echo +set -ex ######################################################################## # @@ -41,4 +42,6 @@ wget https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/sta sudo apt install /tmp/conmon_2.1.2.deb # Install Podman -sudo apt-get -y install podman \ No newline at end of file +sudo apt-get -y install podman + +sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"