Skip to content

Commit

Permalink
Simplify docker image building process
Browse files Browse the repository at this point in the history
  • Loading branch information
mars-lan committed Aug 18, 2024
1 parent 46fca04 commit c56ee15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
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
25 changes: 16 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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 --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

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

0 comments on commit c56ee15

Please sign in to comment.