Skip to content

Commit

Permalink
TMP: is this working?
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Jun 26, 2024
1 parent 76e19a3 commit fccfdbd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 78 deletions.
28 changes: 14 additions & 14 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 0 additions & 20 deletions .github/actions/load/action.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/actions/push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ runs:
- name: Push Image
shell: bash
run: |
docker image ls
docker image push ${{ inputs.registry }}/${{ inputs.tag }}
66 changes: 25 additions & 41 deletions .github/actions/run/action.yml
Original file line number Diff line number Diff line change
@@ -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 <<EOF > exec.sh
#!/bin/bash
whoami
${{ inputs.run }}
EOF
# Start the specified services
make up
cat <<EOF > 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
9 changes: 6 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit fccfdbd

Please sign in to comment.