-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to alpine and improve security & smoke test
- Loading branch information
Showing
14 changed files
with
244 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,72 @@ | ||
FROM python:3.11-slim-bookworm | ||
FROM python:3.11-alpine AS base | ||
|
||
ARG BUILD_CONTEXT | ||
|
||
ENV LIBRDKAFKA_VERSION=1.9.2 | ||
|
||
# Install system dependencies and libraries | ||
RUN apk add --no-cache \ | ||
gcc \ | ||
musl-dev \ | ||
build-base \ | ||
bash \ | ||
oniguruma-dev \ | ||
make \ | ||
autoconf \ | ||
automake \ | ||
libtool \ | ||
curl \ | ||
# librdkafka-dev \ | ||
libffi-dev \ | ||
# Install community librdkafka-dev since the default in alpine is older | ||
&& echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \ | ||
&& echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ | ||
&& apk add --no-cache alpine-sdk "librdkafka@edgecommunity>=${LIBRDKAFKA_VERSION}" "librdkafka-dev@edgecommunity>=${LIBRDKAFKA_VERSION}" \ | ||
&& curl -sSL https://install.python-poetry.org | python3 - \ | ||
&& /root/.local/bin/poetry config virtualenvs.in-project true | ||
|
||
|
||
WORKDIR /app | ||
|
||
COPY ./${BUILD_CONTEXT}/pyproject.toml ./${BUILD_CONTEXT}/poetry.lock /app/ | ||
|
||
RUN /root/.local/bin/poetry install --without dev --no-root --no-interaction --no-ansi --no-cache && pip cache purge | ||
|
||
FROM python:3.11-alpine AS prod | ||
|
||
ARG INTEGRATION_VERSION | ||
ARG BUILD_CONTEXT | ||
|
||
LABEL INTEGRATION_VERSION=${INTEGRATION_VERSION} | ||
# Used to ensure that new integrations will be public, see https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility | ||
LABEL org.opencontainers.image.source https://github.com/port-labs/ocean | ||
LABEL org.opencontainers.image.source=https://github.com/port-labs/ocean | ||
|
||
ENV LIBRDKAFKA_VERSION 1.9.2 | ||
# Install only runtime dependencies | ||
RUN apk add --no-cache \ | ||
librdkafka-dev \ | ||
bash \ | ||
oniguruma-dev \ | ||
# Install community librdkafka-dev since the default in alpine is older | ||
&& echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \ | ||
&& echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ | ||
&& apk add --no-cache alpine-sdk "librdkafka@edgecommunity>=${LIBRDKAFKA_VERSION}" "librdkafka-dev@edgecommunity>=${LIBRDKAFKA_VERSION}" \ | ||
&& test -e /usr/local/share/ca-certificates/cert.crt && update-ca-certificates || true | ||
|
||
WORKDIR /app | ||
|
||
RUN apt update && \ | ||
apt install -y wget make g++ libssl-dev autoconf automake libtool curl librdkafka-dev && \ | ||
apt-get clean | ||
|
||
COPY ./integrations/_infra/init.sh /app/init.sh | ||
|
||
RUN chmod +x /app/init.sh | ||
# Copy dependencies from the build stage | ||
COPY --from=base /app /app | ||
|
||
# Copy the application code | ||
COPY ./${BUILD_CONTEXT} /app | ||
|
||
COPY ./integrations/_infra/Makefile /app/Makefile | ||
|
||
RUN export POETRY_VIRTUALENVS_CREATE=false && make install/prod && pip cache purge | ||
# Ensure that ocean is available for all in path | ||
RUN chmod a+x /app/.venv/bin/ocean \ | ||
&& ln -s /app/.venv/bin/ocean /usr/bin/ocean \ | ||
# # Fix security issues | ||
&& apk upgrade busybox --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main \ | ||
# Clean up old setuptools | ||
&& pip uninstall -y setuptools py3-setuptools | ||
|
||
ENTRYPOINT ./init.sh | ||
# Run the application | ||
CMD ["ocean", "sail"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import List | ||
|
||
from loguru import logger | ||
|
||
from port_ocean.clients.port.client import PortClient | ||
|
||
|
||
async def cleanup_integration(client: PortClient, blueprints: List[str]) -> None: | ||
for blueprint in blueprints: | ||
try: | ||
bp = await client.get_blueprint(blueprint) | ||
if bp is not None: | ||
migration_id = await client.delete_blueprint( | ||
identifier=blueprint, delete_entities=True | ||
) | ||
if migration_id: | ||
await client.wait_for_migration_to_complete( | ||
migration_id=migration_id | ||
) | ||
except Exception as bp_e: | ||
logger.info(f"Skipping missing blueprint ({blueprint}): {bp_e}") | ||
headers = await client.auth.headers() | ||
try: | ||
await client.client.delete( | ||
f"{client.auth.api_url}/integrations/{client.integration_identifier}", | ||
headers=headers, | ||
) | ||
except Exception as int_e: | ||
logger.info( | ||
f"Failed to delete integration ({client.integration_identifier}): {int_e}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Union | ||
|
||
from port_ocean.clients.port.client import PortClient | ||
|
||
|
||
def get_port_client_for_integration( | ||
client_id: str, | ||
client_secret: str, | ||
integration_identifier: str, | ||
integration_type: str, | ||
integration_version: str, | ||
base_url: Union[str, None], | ||
) -> PortClient: | ||
return PortClient( | ||
base_url=base_url or "https://api.getport/io", | ||
client_id=client_id, | ||
client_secret=client_secret, | ||
integration_identifier=integration_identifier, | ||
integration_type=integration_type, | ||
integration_version=integration_version, | ||
) |
Oops, something went wrong.