Skip to content

Commit

Permalink
Run GHA container via docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed May 14, 2024
1 parent a17315e commit 91ea0d0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 48 deletions.
72 changes: 34 additions & 38 deletions .github/actions/run-docker/action.yml
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
4 changes: 1 addition & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ jobs:
- name: Build Docs
uses: ./.github/actions/run-docker
with:
image: ${{ steps.build.outputs.tags }}
options:
version: ${{ steps.build.outputs.version }}
run: |
make update_deps
make docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/extract-locales.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
- name: Extract Locales
uses: ./.github/actions/run-docker
with:
image: ${{ steps.build.outputs.tags }}
options:
version: ${{ steps.build.outputs.version }}
run: |
make update_deps
make extract_locales
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/verify-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
id: failure
uses: ./.github/actions/run-docker
with:
image: ${{ steps.build.outputs.tags }}
version: ${{ steps.build.outputs.version }}
run: |
exit 1
continue-on-error: true
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Check (special characters in command)
uses: ./.github/actions/run-docker
with:
image: ${{ steps.build.outputs.tags }}
version: ${{ steps.build.outputs.version }}
run: |
echo 'this is a question?'
echo 'a * is born'
Expand All @@ -86,8 +86,26 @@ jobs:
- name: Manage py check
uses: ./.github/actions/run-docker
with:
image: ${{ steps.build.outputs.tags }}
options:
version: ${{ steps.build.outputs.version }}
run: |
make update_deps
make check
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- id: build
uses: ./.github/actions/build-docker

- name: Run Test
uses: ./.github/actions/run-docker
with:
version: ${{ steps.build.outputs.version }}
services: ''
run: |
pytest \
-n auto \
-m 'not es_tests and not needs_locales_compilation and not static_assets and not internal_routes_allowed' \
-v src/olympia/amo

0 comments on commit 91ea0d0

Please sign in to comment.