Skip to content

Commit

Permalink
refactor args
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Steiner <[email protected]>
  • Loading branch information
Robert-Steiner committed Sep 16, 2024
1 parent abcaa0b commit 5925692
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 55 deletions.
34 changes: 34 additions & 0 deletions .github/actions/format-docker-build-args/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "format-docker-build-args"
description: "Format the build args to work with the wretry.action"
inputs:
build-args:
description: "List of build-time variables."
outputs:
build-args:
description: "Build args formatted to work with the wretry.action"
value: ${{ steps.build-args.outputs.build-args }}
runs:
using: "composite"
steps:
- id: build-args
shell: python
run: |
import os
# Adds two spaces to the line breaks to ensure proper indentation
# when passing the multi-line string to the wretry.action.
# Without it, the multi-line string is passed like this:
#
# build-args: |
# ARG1=
# ARG2=
# ARG3=
#
# This causes the Docker action to interpret ARG2 and ARG3 as keys instead
# of values ​​of the multi-line string.
build_args = '''${{ inputs.build-args }}'''.replace("\n", "\n ")
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print("build-args<<EOF", file=fh)
print(build_args, file=fh)
print("EOF", file=fh)
61 changes: 6 additions & 55 deletions .github/workflows/_docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,14 @@ jobs:
hash = hashlib.sha256('''${{ inputs.namespace-repository }}
${{ inputs.file-dir }}
${{ inputs.build-args }}'''.encode())
# Adds two spaces to the line breaks to ensure proper indentation
# when passing the multi-line string to the wretry.action.
# Without it, the multi-line string is passed like this:
#
# build-args: |
# ARG1=
# ARG2=
# ARG3=
#
# This causes the Docker action to interpret ARG2 and ARG3 as keys instead
# of values ​​of the multi-line string.
build_args = '''${{ inputs.build-args }}'''.replace("\n", "\n ")
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"id={hash.hexdigest()}", file=fh)
print("build-args<<EOF", file=fh)
print(build_args, file=fh)
print("EOF", file=fh)
- name: Create build args
id: build-args
shell: python
run: python dev/create-docker-build-args.py

- name: Extract metadata (tags, labels) for Docker
id: meta
Expand All @@ -86,45 +76,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1

- name: Test image
uses: Wandalen/wretry.action@6feedb7dedadeb826de0f45ff482b53b379a7844 # v3.5.0
if: matrix.platform.docker == 'linux/amd64'
with:
action: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
attempt_limit: 60 # 60 attempts * (9 secs delay + 1 sec retry) = ~10 mins
attempt_delay: 9000 # 9 secs
with: |
pull: true
platforms: ${{ matrix.platform.docker }}
context: "{{defaultContext}}:${{ inputs.file-dir }}"
load: true
tags: test-container
build-args: |
${{ steps.build-id.outputs.build-args }}
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
if: matrix.platform.docker == 'linux/amd64'

- name: Test image
if: matrix.platform.docker == 'linux/amd64'
env:
FLWR_VERSION: test-container
PROJECT_DIR: e2e-compose
working-directory: src/docker/complete
run: |
flwr new e2e-compose --framework PyTorch --username flower
docker compose -f certs.yml up --build
docker compose -f compose.yml -f with-tls.yml up --build -d
cat <<EOT >> "${PROJECT_DIR}/pyproject.toml"
[tool.flwr.federations.docker-compose-tls]
address = "127.0.0.1:9093"
root-certificates = "../superexec-certificates/ca.crt"
EOT
flwr run e2e-compose docker-compose-tls
timeout 1000 docker compose logs -f superexec | grep -q 'Run finished'
- name: Login to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
Expand All @@ -144,7 +95,7 @@ jobs:
context: "{{defaultContext}}:${{ inputs.file-dir }}"
outputs: type=image,name=${{ inputs.namespace-repository }},push-by-digest=true,name-canonical=true,push=true
build-args: |
${{ steps.build-id.outputs.build-args }}
${{ steps.build-args.outputs.build-args }}
- name: Export digest
run: |
Expand Down

0 comments on commit 5925692

Please sign in to comment.