-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: docker-publish | ||
description: Builds a docker image using nix and publish it to Docker hub. | ||
|
||
inputs: | ||
image_path: | ||
description: The path of the built image that should be loaded | ||
required: true | ||
username: | ||
description: "Docker hub username" | ||
required: true | ||
password: | ||
description: "Docker hub password" | ||
required: true | ||
name: | ||
description: "The name of the container to be published" | ||
required: true | ||
artifact: | ||
description: "The image and tag produced by the nix expression" | ||
required: true | ||
tag: | ||
required: false | ||
default: "" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: docker/login-action@v1 | ||
with: | ||
username: ${{ inputs.username }} | ||
password: ${{ inputs.password }} | ||
- name: Docker load, tag, and push | ||
run: | | ||
# See https://github.com/actions/checkout/issues/760 | ||
git config --global --add safe.directory /__w/composable/composable | ||
docker load --input ${{ inputs.image_path }} | ||
SHA256=$(sha256sum ${{ inputs.image_path }} | cut --delimiter " " --fields 1) | ||
COMMIT_SHA=$(git rev-parse HEAD) | ||
CONTAINER_NAME=${{ inputs.name }} | ||
TEMP_CONTAINER_NAME=${{ inputs.artifact }} | ||
docker tag "${TEMP_CONTAINER_NAME}" "composablefi/${CONTAINER_NAME}:${SHA256}" | ||
docker tag "${TEMP_CONTAINER_NAME}" "composablefi/${CONTAINER_NAME}:${COMMIT_SHA}" | ||
if [[ -n "${{ inputs.tag }}" ]]; then | ||
docker tag "${TEMP_CONTAINER_NAME}" "composablefi/${CONTAINER_NAME}:${{ inputs.tag }}" | ||
fi | ||
if [[ $(git symbolic-ref HEAD) = "refs/heads/main" ]]; then | ||
docker tag "${TEMP_CONTAINER_NAME}" "composablefi/${CONTAINER_NAME}:latest" | ||
fi; | ||
docker push --all-tags "composablefi/${CONTAINER_NAME}" | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: watch-exec | ||
description: Calls commands within a cachix watch-exec wrapper. | ||
|
||
inputs: | ||
command: | ||
description: "The shell command to execute within a watch-exec context" | ||
required: true | ||
working-directory: | ||
description: "Directory to execute command" | ||
required: false | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- run: | | ||
# Marker status code in case of network failure. | ||
STATUS_TRANSIENT_FAILURE=200 | ||
# Maximum retries in case of network failures. | ||
RETRIES=5 | ||
INPUTS_COMMAND="${{ inputs.command }}" | ||
CACHIX="cachix watch-exec --compression-level ${CACHIX_COMPRESSION_LEVEL:-16} --compression-method ${CACHIX_COMPRESSION_METHOD:-"zstd"} --jobs ${CACHIX_JOBS:-16} composable" | ||
NIX_DEBUG_COMMAND="" && [[ $ACTIONS_RUNNER_DEBUG = "true" ]] && NIX_DEBUG_COMMAND='--print-build-logs --debug --show-trace --verbose --keep-going' | ||
HAPPY_CMD="${CACHIX?} ${INPUTS_COMMAND?} --no-update-lock-file --accept-flake-config ${NIX_DEBUG_COMMAND} -L 2> >(tee --append $LOG_FILE >&2)" | ||
SLOW_CMD="${CACHIX?} ${INPUTS_COMMAND?} --no-update-lock-file --accept-flake-config --show-trace --fallback -L 2 ${NIX_DEBUG_COMMAND} > >(tee --append $LOG_FILE >&2)" | ||
printf "will try execute '${HAPPY_CMD?}'" | ||
# Marker that a network error occurred. | ||
BAD="HTTP error 200 ('')" | ||
LOG_FILE=/tmp/out.log | ||
function run() { | ||
eval "${HAPPY_CMD?}" | ||
STATUS_CODE=$? | ||
if [[ $STATUS_CODE -ne 0 ]] ; then | ||
C=$(grep -c "HTTP error 200" $LOG_FILE) | ||
if [[ $C -gt 0 ]]; then | ||
STATUS_CODE=$STATUS_TRANSIENT_FAILURE | ||
fi | ||
fi | ||
} | ||
try=0 | ||
while [[ "${try?}" -le "${RETRIES?}" ]]; do | ||
if [[ "${try?}" -eq "${RETRIES?}" ]] ; then | ||
eval "${SLOW_CMD?}" | ||
STATUS_CODE=$? | ||
break | ||
fi | ||
run | ||
if [[ $STATUS_CODE -eq 0 ]] ; then | ||
break | ||
fi | ||
if [[ $STATUS_CODE -ne 0 ]] && [[ $STATUS_CODE -ne $STATUS_TRANSIENT_FAILURE ]] ; then | ||
break | ||
fi | ||
((try=try+1)) | ||
done | ||
exit $((STATUS_CODE)) | ||
shell: "bash" | ||
working-directory: ${{ inputs.working-directory }} |