Skip to content

Commit

Permalink
Refactor dockerize and export (#1096)
Browse files Browse the repository at this point in the history
* Refactor workspace export; fmt

Signed-off-by: Shah, Karan <[email protected]>

* Refactor `fx workspace export` and `fx workspace dockerize`

Signed-off-by: Shah, Karan <[email protected]>

* Eliminate base image build step

Signed-off-by: Shah, Karan <[email protected]>

* mark flag

Signed-off-by: Shah, Karan <[email protected]>

* Fuse build layer

Signed-off-by: Shah, Karan <[email protected]>

* Add --no-cache option; export ws first

Signed-off-by: Shah, Karan <[email protected]>

* Use OpenFL git source instead of local

Signed-off-by: Shah, Karan <[email protected]>

* Generic username, disable pip cache

Signed-off-by: Shah, Karan <[email protected]>

* configurable source/branch with default

Signed-off-by: Shah, Karan <[email protected]>

* Configurable one-liner revision flag

Signed-off-by: Shah, Karan <[email protected]>

* Readable tag instead of commit hash

Signed-off-by: Shah, Karan <[email protected]>

* Test GITHUB_HEAD_REF for CI

Signed-off-by: Shah, Karan <[email protected]>

* another try

Signed-off-by: Shah, Karan <[email protected]>

---------

Signed-off-by: Shah, Karan <[email protected]>
  • Loading branch information
MasterSkepticista authored Oct 29, 2024
1 parent 1b051b0 commit 85c5efc
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 187 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/dockerization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ jobs:
python -m pip install --upgrade pip
pip install .
- name: Build base image
run: |
docker build -t openfl -f openfl-docker/Dockerfile.base .
- name: Create workspace image
run: |
fx workspace create --prefix example_workspace --template keras_cnn_mnist
cd example_workspace
fx plan initialize -a localhost
fx workspace dockerize --base_image openfl
fx workspace dockerize --save --revision https://github.com/${GITHUB_REPOSITORY}.git@${{ github.event.pull_request.head.sha }}
- name: Create certificate authority for workspace
run: |
Expand Down Expand Up @@ -76,7 +72,7 @@ jobs:
- name: Load workspace image
run: |
cd example_workspace
docker load -i example_workspace_image.tar
docker load -i example_workspace.tar
- name: Run aggregator and collaborator
run: |
Expand Down
23 changes: 11 additions & 12 deletions openfl-docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
# ------------------------------------
# OpenFL Base Image
# $> docker build . -t openfl -f Dockerfile.base [--build-arg OPENFL_REVISION=GIT_URL@COMMIT_ID]
# ------------------------------------
FROM ubuntu:22.04 as base
FROM ubuntu:22.04 AS base

# Configure network proxy, if required, in ~/.docker/config.json
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -13,28 +14,26 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
apt-get update && \
apt-get install -y \
git \
python3-pip \
python3.10-dev \
ca-certificates \
build-essential \
git \
--no-install-recommends && \
apt-get purge -y linux-libc-dev && \
rm -rf /var/lib/apt/lists/*
RUN apt-get purge -y linux-libc-dev

# Create an unprivileged user.
RUN groupadd -g 1001 default && \
useradd -m -u 1001 -g default openfl
USER openfl
useradd -m -u 1001 -g default user
USER user
WORKDIR /home/user
ENV PATH=/home/user/.local/bin:$PATH

# Install OpenFL.
WORKDIR /home/openfl
COPY --chown=openfl:default . .
ENV PATH=/home/openfl/.local/bin:$PATH
ARG OPENFL_REVISION=https://github.com/securefederatedai/[email protected]
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -e .

# Download thirdparty licenses.
RUN INSTALL_SOURCES=yes /home/openfl/openfl-docker/licenses.sh
pip install --no-cache-dir git+${OPENFL_REVISION} && \
INSTALL_SOURCES=yes /home/user/.local/lib/python3.10/site-packages/openfl-docker/licenses.sh

CMD ["/bin/bash"]
8 changes: 3 additions & 5 deletions openfl-docker/Dockerfile.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ FROM ${BASE_IMAGE}

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER openfl
USER user
ARG WORKSPACE_NAME
COPY ${WORKSPACE_NAME}.zip .

WORKDIR /home/openfl
RUN fx workspace import --archive ${WORKSPACE_NAME}.zip && \
pip install -r ${WORKSPACE_NAME}/requirements.txt
pip install --no-cache-dir -r ${WORKSPACE_NAME}/requirements.txt

WORKDIR /home/openfl/${WORKSPACE_NAME}
WORKDIR /home/user/${WORKSPACE_NAME}
CMD ["/bin/bash"]
Loading

0 comments on commit 85c5efc

Please sign in to comment.