Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify docker image building process #954

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Setup Poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ env.POETRY_VERSION }}

- name: Export requirements.txt
run: poetry export -E all -f requirements.txt --output requirements.txt

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
Expand Down
30 changes: 21 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
FROM python:3.8-slim AS base

FROM python:3.8-slim
# Builder - Dependencies
FROM base AS builder

RUN apt-get clean
RUN apt-get update
RUN apt-get install -y git build-essential libsasl2-dev
RUN pip install poetry

COPY ./requirements.txt /src/requirements.txt
COPY pyproject.toml poetry.lock src/
WORKDIR /src

RUN pip install -r /src/requirements.txt --no-deps
RUN poetry export \
--without dev \
--all-extras \
--format=requirements.txt \
--output=requirements.txt

RUN rm -rf /src
# Runtime
FROM base AS runtime

COPY . /src
RUN apt-get clean
RUN apt-get update
RUN apt-get install -y git build-essential libsasl2-dev

RUN pip install '/src[all]'
COPY --from=builder /src/requirements.txt /dep/requirements.txt
RUN pip install -r /dep/requirements.txt --no-deps
RUN rm -rf /dep

COPY . src/
RUN pip install '/src[all]'
RUN rm -rf /src

CMD ["sh", "-c", "metaphor ${CONNECTOR} ${CONFIG_FILE}"]
8 changes: 2 additions & 6 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We follow [Semantic Versioning](https://semver.org/) and [docker tagging best pr

## Running

The Docker image contains all the required dependencies so running it should be very straightforward. Note that you'll need to provide your local config file to the Docker container via [bind mounts](https://docs.docker.com/storage/bind-mounts/). For example,
The Docker image contains all the required dependencies so running it should be very straightforward. Note that you'll need to provide your local config file to the Docker container via [bind mounts](https://docs.docker.com/storage/bind-mounts/). For example, this command passes your local config file (`~/config.yml`) to the docker image,

```sh
docker run -it --rm \
Expand All @@ -17,7 +17,7 @@ docker run -it --rm \
metaphor bigquery /config.yml
```

If you configure to write the [output](../metaphor/common/docs/output.md) to a local directory instead of an S3 path, you'll also need to bind mount the output directory to access the files, e.g.
If you configure to write the [output](../metaphor/common/docs/output.md) to a local directory instead of an S3 path, you'll also need to bind mount the output directory (`~/output` in this case) to access the files, e.g.

```yml
# ~/config.yml
Expand Down Expand Up @@ -45,10 +45,6 @@ To build and publish an image with the `test` tag for testing, run the following
# Assuming not yet logged in
docker login

# Our Dockerfile refereneces requirements.txt to decrease build time. Make sure
# to run this before running `docker build`.
poetry export --all-extras --format=requirements.txt --output=requirements.txt

docker build --platform linux/amd64 -t metaphordata/connectors:test .
docker push metaphordata/connectors:test
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.14.78"
version = "0.14.79"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down
Loading