diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 69542465..a10eed6c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,6 +27,9 @@ jobs: url: ${{ vars.PYPI_PROJECT_URL }} permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + outputs: + version: ${{ steps.release-inputs.outputs.version }} + is-docker-release: ${{ steps.semver.outputs.is-pre-release == 0 }} steps: - name: Check out repository @@ -43,6 +46,13 @@ jobs: version=$(hatch version) archive_name=dbt-postgres-$version-${{ inputs.deploy-to }} echo "archive-name=$archive_name" >> $GITHUB_OUTPUT + echo "version=version" >> $GITHUB_OUTPUT + + - name: Audit version to determine if it is a pre-release + id: semver + uses: dbt-labs/actions/parse-semver@v1.1.0 + with: + version: ${{ steps.release-inputs.outputs.version }} - name: Build `dbt-postgres` uses: dbt-labs/dbt-adapters/.github/actions/build-hatch@main @@ -54,3 +64,14 @@ jobs: with: pypi-repository-url: ${{ vars.PYPI_REPOSITORY_URL }} archive-name: ${{ steps.release-inputs.outputs.archive-name }} + + docker-release: + name: "Docker Release" + needs: [release] + if: ${{ needs.release.outputs.is-docker-release }} + permissions: + packages: write + uses: dbt-labs/dbt-release/.github/workflows/release-docker.yml@main + with: + package: "dbt-postgres" + version_number: ${{ needs.release.outputs.version }} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..a87beac3 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +ARG build_for=linux/amd64 + +FROM --platform=$build_for python:3.10.7-slim-bullseye as base + +# ref is updated automatically every final release via bumpversion +ARG dbt_postgres_ref=dbt-postgres@v1.7.10 + +RUN apt-get update \ + && apt-get dist-upgrade -y \ + && apt-get install -y --no-install-recommends \ + git \ + ssh-client \ + software-properties-common \ + make \ + build-essential \ + ca-certificates \ + libpq-dev \ + && apt-get clean \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +ENV PYTHONIOENCODING=utf-8 +ENV LANG=C.UTF-8 + +RUN python -m pip install --upgrade pip setuptools wheel --no-cache-dir + +WORKDIR /usr/app/dbt/ +ENTRYPOINT ["dbt"] + +FROM base as dbt-postgres +RUN python -m pip install --no-cache-dir "dbt-postgres @ git+https://github.com/dbt-labs/${dbt_postgres_ref}" diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..f9d01513 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,70 @@ +# Docker for dbt +This docker file is suitable for building dbt Docker images locally or using with CI/CD to automate populating a container registry. + + +## Building an image: +This Dockerfile can create images for the following target: `dbt-postgres` + +In order to build a new image, run the following docker command. +``` +docker build --tag --target dbt-postgres +``` +--- +> **Note:** Docker must be configured to use [BuildKit](https://docs.docker.com/develop/develop-images/build_enhancements/) in order for images to build properly! + +--- + +By default the images will be populated with the most recent release of `dbt-postgres`. If you need to use a different version you can specify it by git ref using the `--build-arg` flag: +``` +docker build --tag \ + --target dbt-postgres \ + --build-arg dbt_postgres_ref= \ + +``` + +### Examples: +To build an image named "my-dbt" that supports Snowflake using the latest releases: +``` +cd dbt-core/docker +docker build --tag my-dbt --target dbt-postgres . +``` + +To build an image named "my-other-dbt" that supports Snowflake using the adapter version 1.0.0b1: +``` +cd dbt-core/docker +docker build \ + --tag my-other-dbt \ + --target dbt-postgres \ + --build-arg dbt_postgres_ref=dbt-postgres@v1.0.0b1 \ + . +``` + +## Special cases +There are a few special cases worth noting: + +* If you need to build against another architecture (linux/arm64 in this example) you can override the `build_for` build arg: +``` +docker build --tag my_dbt \ + --target dbt-postgres \ + --build-arg build_for=linux/arm64 \ + +``` + +Supported architectures can be found in the python docker [dockerhub page](https://hub.docker.com/_/python). + +## Running an image in a container: +The `ENTRYPOINT` for this Dockerfile is the command `dbt` so you can bind-mount your project to `/usr/app` and use dbt as normal: +``` +docker run \ + --network=host \ + --mount type=bind,source=path/to/project,target=/usr/app \ + --mount type=bind,source=path/to/profiles.yml,target=/root/.dbt/profiles.yml \ + my-dbt \ + ls +``` +--- +**Notes:** +* Bind-mount sources _must_ be an absolute path +* You may need to make adjustments to the docker networking setting depending on the specifics of your data warehouse/database host. + +--- diff --git a/docker/test.sh b/docker/test.sh new file mode 100755 index 00000000..f7b86352 --- /dev/null +++ b/docker/test.sh @@ -0,0 +1,22 @@ +# - VERY rudimentary test script to run latest + specific branch image builds and test them all by running `--version` +# TODO: create a real test suite + +clear \ +&& echo "\n\n"\ +"########################################\n"\ +"##### Testing dbt-postgres latest #####\n"\ +"########################################\n"\ +&& docker build --tag dbt-postgres \ + --target dbt-postgres \ + docker \ +&& docker run dbt-postgres --version \ +\ +&& echo "\n\n"\ +"#########################################\n"\ +"##### Testing dbt-postgres-1.0.0b1 #####\n"\ +"#########################################\n"\ +&& docker build --tag dbt-postgres-1.0.0b1 \ + --target dbt-postgres \ + --build-arg dbt_postgres_ref=dbt-postgres@v1.0.0b1 \ + docker \ +&& docker run dbt-postgres-1.0.0b1 --version