diff options
author | 2021-02-04 16:13:48 -0800 | |
---|---|---|
committer | 2021-02-04 17:08:59 -0800 | |
commit | 21673cee3105e6595e5a77c5b13fb17b2f9bb173 (patch) | |
tree | 3fa5ca111bc9129125883fa4c426d69512d119ef | |
parent | Document configuration thoroughly (diff) |
CI: use Docker Compose to run the container
Avoid redundant specification of Docker settings.
The compose file is set up to build all stages. This makes sense for
local development; both an interactive shell and running the webserver
are useful. Therefore, the image built is tagged "snekbox:dev".
However, CI does not need to run a webserver. It is therefore sufficient
for it to only build to the venv stage, and it does exactly that. The
image in CI is tagged as "snekbox-venv:<git sha>".
To facilitate the discrepancy in image tags, the suffix for the image
tag can be set with the new IMAGE_SUFFIX environment variable. Docker
Compose will use this to determine the image from which to create a
container.
A TTY needs to be allocated to prevent the container from exiting
immediately after starting. This is probably because the entrypoint
is Python (inherited from the base image), and the REPL relies on a TTY.
-rw-r--r-- | .github/workflows/lint-test-build-push.yaml | 26 | ||||
-rw-r--r-- | docker-compose.yml | 3 |
2 files changed, 10 insertions, 19 deletions
diff --git a/.github/workflows/lint-test-build-push.yaml b/.github/workflows/lint-test-build-push.yaml index d77ead1..338e301 100644 --- a/.github/workflows/lint-test-build-push.yaml +++ b/.github/workflows/lint-test-build-push.yaml @@ -81,37 +81,27 @@ jobs: tags: ghcr.io/python-discord/snekbox-venv:${{ steps.sha_tag.outputs.tag }} - name: Start Container - run: >- - docker run - --tty - --detach - --name snekbox_test - --privileged - --hostname pdsnk-dev - -e PYTHONDONTWRITEBYTECODE=1 - -e PIPENV_PIPFILE='/snekbox/Pipfile' - --volume "${PWD}":"${PWD}" - --workdir "${PWD}" - --entrypoint /bin/bash - ghcr.io/python-discord/snekbox-venv:${{ steps.sha_tag.outputs.tag }} + run: | + export IMAGE_SUFFIX='-venv:${{ steps.sha_tag.outputs.tag }}' + docker-compose up --no-build -d # One of the unit tests needs to import numpy. - name: Install dependencies run: >- - docker exec snekbox_test /bin/bash -c + docker exec snekbox_dev /bin/bash -c 'pipenv install --system --deploy --dev && pip install numpy' # Required by pre-commit. - name: Install git run: >- - docker exec snekbox_test /bin/bash -c + docker exec snekbox_dev /bin/bash -c 'apt-get -y update && apt-get install -y git=1:2.20.*' # pre-commit's venv doesn't work with user installs. # Skip the flake8 hook because the following step will run it. - name: Run pre-commit hooks run: >- - docker exec snekbox_test /bin/bash -c + docker exec snekbox_dev /bin/bash -c 'PIP_USER=0 SKIP=flake8 pre-commit run --all-files' # This runs `flake8` in the container and asks `flake8` to output @@ -121,7 +111,7 @@ jobs: # wrong where. - name: Run linter run: >- - docker exec snekbox_test /bin/bash -c + docker exec snekbox_dev /bin/bash -c 'flake8 --format "::error file=%(path)s,line=%(row)d,col=%(col)d::[flake8] %(code)s: %(text)s"' @@ -135,7 +125,7 @@ jobs: run: | echo '::set-output name=started::true' cmd='coverage run -m unittest; coverage report -m' - docker exec snekbox_test /bin/bash -c "${cmd}" + docker exec snekbox_dev /bin/bash -c "${cmd}" # Set-up a Python version to process the coverage reports # Note: This step runs even if the test step failed to make diff --git a/docker-compose.yml b/docker-compose.yml index d073dd1..f546024 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,11 +5,12 @@ services: container_name: snekbox_dev hostname: snekbox_dev privileged: true - image: ghcr.io/python-discord/snekbox:dev + image: ghcr.io/python-discord/snekbox${IMAGE_SUFFIX:-:dev} ports: - 8060:8060 init: true ipc: none + tty: true working_dir: $PWD environment: DEBUG: 1 |