From fccfdbd6bc66b9b2ff4fe0c405fb8fa6046fffb1 Mon Sep 17 00:00:00 2001 From: Kevin Meinhardt Date: Wed, 26 Jun 2024 13:08:04 +0200 Subject: [PATCH] TMP: is this working? --- .github/actions/build/action.yml | 28 +++++++------- .github/actions/load/action.yml | 20 ---------- .github/actions/push/action.yml | 1 + .github/actions/run/action.yml | 66 ++++++++++++-------------------- .github/workflows/push.yml | 9 +++-- 5 files changed, 46 insertions(+), 78 deletions(-) delete mode 100644 .github/actions/load/action.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index f4ac09c..575d3fa 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -11,9 +11,6 @@ inputs: default: "false" outputs: - tags: - description: "The Docker tags for the image" - value: ${{ steps.meta.outputs.tags }} version: description: "The version for the image" value: ${{ steps.meta.outputs.version }} @@ -27,9 +24,9 @@ outputs: runs: using: "composite" steps: - # Setup docker to build for multiple architectures - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 with: @@ -65,19 +62,17 @@ runs: ${{ steps.meta.outputs.json }} EOF - tag=$(cat meta.json | jq -r '.tags[0]') - tag_cache="$tag-cache" - - echo "tag=$tag" >> $GITHUB_OUTPUT - echo "tag_cache=$tag_cache" >> $GITHUB_OUTPUT - + echo "tag=$(cat meta.json | jq -r '.tags[0]')" >> $GITHUB_OUTPUT cat $GITHUB_OUTPUT - name: Tar file id: tar shell: bash + # image.tar is the name of the compressed image file + # This should be kept in sync with ./.github/actions/run/action.yml + # That loads the image from this file run: | - echo "path=/tmp/${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT + echo "path=/tmp/image.tar" >> $GITHUB_OUTPUT - name: Build Image id: build @@ -87,8 +82,6 @@ runs: with: targets: app load: true - set: | - *.output=type=docker,dest=${{ steps.tar.outputs.path }} - name: Get image digest id: digest @@ -98,10 +91,17 @@ runs: echo "digest=$(cat metadata.json | jq -r '.app."containerimage.digest"')" >> $GITHUB_OUTPUT cat $GITHUB_OUTPUT + - name: Save Docker Image to Tar + shell: bash + run: | + docker save -o /tmp/image.tar ${{ steps.tag.outputs.tag }} + - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: ${{ steps.meta.outputs.version }} + # The artifact name should be kept in sync with + # ./.github/actions/run/action.yml which downloads the artifact + name: docker-image path: ${{ steps.tar.outputs.path }} retention-days: 1 compression-level: 9 diff --git a/.github/actions/load/action.yml b/.github/actions/load/action.yml deleted file mode 100644 index 73f716c..0000000 --- a/.github/actions/load/action.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: 'Docker Load image from tar file' -description: 'Loads a docker image from a tar file' -inputs: - version: - required: true - description: "The docker image version you want to load" - -runs: - using: "composite" - steps: - - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.version }} - path: /tmp/ - - - name: Load image - shell: bash - run: | - docker load < /tmp/${{ inputs.version }} - docker image ls diff --git a/.github/actions/push/action.yml b/.github/actions/push/action.yml index f6087fb..b349062 100644 --- a/.github/actions/push/action.yml +++ b/.github/actions/push/action.yml @@ -28,4 +28,5 @@ runs: - name: Push Image shell: bash run: | + docker image ls docker image push ${{ inputs.registry }}/${{ inputs.tag }} diff --git a/.github/actions/run/action.yml b/.github/actions/run/action.yml index 3793d4d..3fb45d3 100644 --- a/.github/actions/run/action.yml +++ b/.github/actions/run/action.yml @@ -1,58 +1,42 @@ name: 'Docker Run Action' description: 'Run a command in a new container' inputs: - image: - description: "The Docker image to run" + tag: + description: 'The docker image tag to run.' required: true - options: - description: 'Options' - required: false run: description: 'Run command in container' required: true runs: using: 'composite' steps: - - name: Validate inputs + - uses: actions/download-artifact@v4 + with: + # The artifact name should be kept in sync with + # ./.github/actions/build/action.yml which uploads the artifact + name: docker-image + path: /tmp/ + + # image.tar is the name of the compressed image file + # This should be kept in sync with ./.github/actions/build/action.yml + - name: Load image shell: bash run: | - if [[ -z "${{ inputs.image }}" ]]; then - echo "Image is required" - exit 1 - fi - if [[ -z "${{ inputs.run }}" ]]; then - echo "Run is required" - exit 1 - fi + docker load < /tmp/image.tar + docker image ls + - name: Run Docker Container shell: bash + env: + DOCKER_TAG: ${{ inputs.tag }} run: | - cat < exec.sh - #!/bin/bash - whoami - ${{ inputs.run }} - EOF + # Start the specified services + make up - cat < root.sh - #!/bin/bash - whoami - su -s /bin/bash -c './exec.sh' root + # Exec the run command in the container + # quoted 'EOF' to prevent variable expansion + cat <<'EOF' | docker compose exec --user root app sh + #!/bin/bash + whoami + ${{ inputs.run }} EOF - - # Make both files executable - chmod +x exec.sh - chmod +x root.sh - - # Debug info - echo "############" - cat root.sh - echo "############" - echo "############" - cat exec.sh - echo "############" - - # Execute inside docker container - cat root.sh | docker run ${{ inputs.options }} \ - -i --rm -u 0 \ - -v $(pwd):/app \ - ${{ inputs.image }} bash diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 13a5286..a8f7d3e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest outputs: - version: ${{ steps.build.outputs.version }} + tag: ${{ steps.build.outputs.tag }} steps: - uses: actions/checkout@v4 @@ -46,8 +46,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/load + - uses: ./.github/actions/run with: - version: ${{ needs.build.outputs.version }} + tag: ${{ needs.build.outputs.tag }} + run: | + echo "Hello world" + npm run test