-
Notifications
You must be signed in to change notification settings - Fork 1
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
5 changed files
with
46 additions
and
78 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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -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 |
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