-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run GHA container via docker compose
- Loading branch information
Showing
4 changed files
with
59 additions
and
48 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 |
---|---|---|
@@ -1,55 +1,51 @@ | ||
name: 'Docker Run Action' | ||
description: 'Run a command in a new container' | ||
inputs: | ||
image: | ||
description: "The Docker image to run" | ||
version: | ||
description: 'The version of the image to run' | ||
required: true | ||
options: | ||
description: 'Options' | ||
required: false | ||
run: | ||
description: 'Run command in container' | ||
required: true | ||
services: | ||
description: 'List of services to start' | ||
required: false | ||
default: 'web' | ||
compose_file: | ||
description: 'The docker-compose file to use' | ||
required: false | ||
default: 'docker-compose.yml' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- id: id | ||
shell: bash | ||
run: | | ||
echo "id=$(id -u)" >> $GITHUB_OUTPUT | ||
- name: Run Docker Container | ||
shell: bash | ||
env: | ||
DOCKER_VERSION: ${{ inputs.version }} | ||
COMPOSE_FILE: ${{ inputs.compose_file }} | ||
DOCKER_SERVICES: ${{ inputs.services }} | ||
HOST_UID: ${{ steps.id.outputs.id }} | ||
run: | | ||
# Export .env file with host user info | ||
make -f Makefile-os create_env_file | ||
if [[ -z "${{ inputs.run }}" ]]; then | ||
echo "run input is required" | ||
exit 1 | ||
fi | ||
cat <<EOF > exec.sh | ||
#!/bin/bash | ||
whoami | ||
${{ inputs.run }} | ||
EOF | ||
# Start the specified services | ||
make up | ||
cat <<EOF > root.sh | ||
#!/bin/bash | ||
whoami | ||
./docker/entrypoint.sh | ||
su -s /bin/bash -c './exec.sh' olympia | ||
# Exec the run command in the container | ||
# quoted 'EOF' to prevent variable expansion | ||
cat <<'EOF' | docker compose exec --user olympia web sh | ||
${{ 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 }} \ | ||
--env-file .env \ | ||
-i --rm -u 0 \ | ||
-v $(pwd):/data/olympia \ | ||
-v ./deps:/deps \ | ||
-v ./package.json:/deps/package.json \ | ||
-v ./package-lock.json:/deps/package-lock.json \ | ||
${{ inputs.image }} bash | ||
- name: Logs | ||
shell: bash | ||
if: failure() | ||
run: docker compose logs |
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
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