Skip to content

Commit

Permalink
Fix docker build for server & testbed server
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Jan 29, 2024
1 parent 89e737c commit 95c0a23
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/test-server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

import time
from urllib.request import Request, urlopen


def can_connect_to_testbed(r: Request) -> bool:
MAX_RETRIES = 10
DURATION_BETWEEN_RETRIES = 1

for i in range(MAX_RETRIES):
try:
urlopen(r)
except Exception as exc:
print(f"Try {i + 1}/{MAX_RETRIES}: {exc}")
time.sleep(DURATION_BETWEEN_RETRIES)
continue
else:
return True
return False


if __name__ == "__main__":
r = Request("http://127.0.0.1:6777/", method="GET")
print(f"Will connect to testbed server on: {r.get_full_url()}")

if can_connect_to_testbed(r):
print("Success")
else:
raise SystemExit("Cannot connect to Parsec server :(")
29 changes: 29 additions & 0 deletions .github/workflows/docker-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ jobs:
flavor: |
latest=${{ github.event_name == 'push' && github.ref_type == 'tag' }}
- name: Build and export to Docker
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
id: build
with:
context: .
file: server/packaging/server/server.dockerfile
load: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
push: false
timeout-minutes: 20

- name: Start docker test container
id: test-container
run: |
(
echo -n "id=";
docker run --detach --publish 6777:6777 --rm --name=parsec-server ${{ steps.build.outputs.imageid }} -- run --port=6777 --dev
) | tee $GITHUB_OUTPUT
timeout-minutes: 1

- name: Test docker image
run: python .github/scripts/test-server.py
timeout-minutes: 1

- name: Stop docker test container
run: docker container stop ${{ steps.test-container.outputs.id }}
timeout-minutes: 1

- name: Image to be published
run: echo ${{ steps.metadata.outputs.tags }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
timeout-minutes: 1

- name: Test docker image
run: python .github/scripts/test-testbed-server.py
run: python .github/scripts/test-server.py
timeout-minutes: 1

- name: Stop docker test container
Expand Down
2 changes: 1 addition & 1 deletion server/packaging/server/in-docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ POETRY_LIBPARSEC_BUNDLE_EXTRA_SHARED_LIBRARIES=false \
pip install ./server

# Basic check to see if the wheel looks like it's well built.
(cd / && /server/venv/bin/parsec --version)
./venv/bin/parsec --version
6 changes: 3 additions & 3 deletions server/packaging/server/server.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

FROM python:3.12 AS builder

WORKDIR /server
WORKDIR /work

# Map source, cannot just do `ADD --link . .` otherwise modifying the current
# file will invalidate the cache.
Expand Down Expand Up @@ -43,12 +43,12 @@ USER parsec:parsec
# Copy the venv from the builder
# Important: Use the same path as the builder so the venv scripts can run
WORKDIR /server
COPY --chown=1234:1234 --from=builder /server/venv /server/venv
COPY --chown=1234:1234 --from=builder /work/venv /server/venv

# Add venv/bin to PATH to make `parsec` available
ENV PATH "/server/venv/bin:$PATH"

# Define entry point
EXPOSE 6777
ENTRYPOINT ["parsec", "backend"]
ENTRYPOINT ["parsec"]
CMD ["run", "--port=6777"]
2 changes: 1 addition & 1 deletion server/packaging/testbed-server/in-docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ pip install ./server
rm -rf ./venv/lib/python3.12/site-packages/{boto3,botocore,pip,setuptools}

# Basic check to see if the wheel looks like it's well built.
(cd / && /server/venv/bin/parsec --version)
./venv/bin/parsec --version
3 changes: 3 additions & 0 deletions server/packaging/testbed-server/testbed-server.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ WORKDIR /testbed

COPY --chown=1234:1234 --from=builder /work/venv /testbed/venv

# Add venv/bin to PATH to make `parsec` available
ENV PATH "/testbed/venv/bin:$PATH"

EXPOSE 6777
ENTRYPOINT ["parsec", "testbed", "--host", "0.0.0.0", "--port", "6777"]
CMD []

0 comments on commit 95c0a23

Please sign in to comment.