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

Add docker release to the full release process for final releases #51

Merged
merged 50 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3048bfc
add docker release to release pipeline
mikealfare Apr 5, 2024
4d9292f
changelog
mikealfare Apr 5, 2024
db3d70e
changelog
mikealfare Apr 5, 2024
7f240c0
update dependabot to include Docker
mikealfare Apr 10, 2024
acf410d
Merge branch 'refs/heads/main' into config/docker-release
mikealfare Apr 13, 2024
938fc07
update to align with other docker release pipelines
mikealfare Apr 13, 2024
8ae7fc0
removed defaulted input for docker package
mikealfare Apr 15, 2024
9862ed6
point back to main
mikealfare Apr 15, 2024
6b935b2
remove changie entry
mikealfare Apr 15, 2024
619641f
add github release
mikealfare Apr 16, 2024
858e994
add github release
mikealfare Apr 16, 2024
5323d3f
add github release
mikealfare Apr 16, 2024
41f665c
add github release
mikealfare Apr 16, 2024
07eb152
add release prep workflow
mikealfare Apr 16, 2024
5af9942
add release prep workflow to release workflow
mikealfare Apr 16, 2024
a8b0048
Merge branch 'main' into config/docker-release
mikealfare Apr 16, 2024
94b8d3c
fix core team workflow ref
mikealfare Apr 16, 2024
0a41a9f
Merge remote-tracking branch 'origin/config/docker-release' into conf…
mikealfare Apr 16, 2024
eb8d083
fix workflow ref
mikealfare Apr 16, 2024
41f4864
pass secrets to release prep workflow
mikealfare Apr 16, 2024
f2c63dc
pass secrets to release prep workflow
mikealfare Apr 16, 2024
ddb29b6
allow for only docker release, don’t release docker when deploying to…
emmyoop Apr 17, 2024
45952e7
Update docker/Dockerfile
mikealfare Apr 26, 2024
0d0a074
Merge branch 'refs/heads/main' into config/docker-release
mikealfare Apr 26, 2024
41ef500
Merge branch 'refs/heads/main' into config/docker-release
mikealfare May 2, 2024
a7497e3
sync with main
mikealfare May 2, 2024
5be5dba
clean up test script
mikealfare May 2, 2024
e67d140
pull branch through to release workflow
mikealfare May 2, 2024
1ece62d
remove sha from workflow
mikealfare May 2, 2024
3a0fb25
fix concurrency id
mikealfare May 2, 2024
4ab3ecd
fix action reference
mikealfare May 2, 2024
35515ed
fix action reference
mikealfare May 2, 2024
de47a33
add postgres setup to integration tests
mikealfare May 2, 2024
793f5d9
Merge branch 'main' into config/docker-release
mikealfare May 3, 2024
e7e61df
Merge branch 'main' into config/docker-release
mikealfare May 13, 2024
25790ff
Merge branch 'main' into config/docker-release
mikealfare May 13, 2024
0530d96
Merge branch 'main' into config/docker-release
mikealfare May 14, 2024
e1fd3ef
remove owner portion from repo name
mikealfare May 14, 2024
ebe2b5f
skip pypi and github release when docker only
mikealfare May 14, 2024
527871a
Merge branch 'main' into config/docker-release
mikealfare May 14, 2024
63c82e1
point docker release to dev branch for now
mikealfare May 14, 2024
45a024a
Merge remote-tracking branch 'origin/config/docker-release' into conf…
mikealfare May 14, 2024
9cde4cf
fix release branch logic
mikealfare May 14, 2024
3291829
fix repository name reference
mikealfare May 14, 2024
acc1df4
fix branch references
mikealfare May 14, 2024
6a39cbd
point everything back to main
mikealfare May 15, 2024
2931917
Merge branch 'main' into config/docker-release
mikealfare May 15, 2024
1e7ad5b
adding some requested docs
mikealfare May 20, 2024
26b6332
Merge remote-tracking branch 'origin/config/docker-release' into conf…
mikealfare May 20, 2024
201f3e2
remove unused script
mikealfare May 20, 2024
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240405-184129.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Automate the Docker release as part of the PyPI release
time: 2024-04-05T18:41:29.303294-04:00
custom:
Author: mikealfare
Issue: "51"
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ updates:
schedule:
interval: "weekly"
rebase-strategy: "disabled"
- package-ecosystem: "docker"
directory: "/docker"
schedule:
interval: "weekly"
rebase-strategy: "disabled"
VersusFacit marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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 }}

steps:
- name: Check out repository
Expand All @@ -43,6 +45,7 @@ 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: Build `dbt-postgres`
uses: dbt-labs/dbt-adapters/.github/actions/build-hatch@main
Expand All @@ -54,3 +57,15 @@ 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: ${{ !failure() && !cancelled() }}
permissions:
packages: write
uses: dbt-labs/dbt-release/.github/workflows/release-docker.yml@docker-release
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
with:
package: ${{ github.event.repository.name }}
version_number: ${{ needs.release.outputs.version }}
test_run: ${{ inputs.deploy-to == 'test' }}
30 changes: 17 additions & 13 deletions dbt/adapters/postgres/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@

@dataclass(frozen=True, eq=False, repr=False)
class PostgresRelation(BaseRelation):
renameable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset(
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
))
replaceable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset(
{
RelationType.View,
RelationType.Table,
}
))
renameable_relations: FrozenSet[RelationType] = field(
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
default_factory=lambda: frozenset(
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
)
)
replaceable_relations: FrozenSet[RelationType] = field(
default_factory=lambda: frozenset(
{
RelationType.View,
RelationType.Table,
}
)
)

def __post_init__(self):
# Check for length of Postgres table/view names.
Expand Down
37 changes: 37 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# this image gets published to GHCR for production use
ARG py_version=3.10.7
mikealfare marked this conversation as resolved.
Show resolved Hide resolved

FROM python:$py_version-slim-bullseye as base

RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends \
build-essential=12.9 \
ca-certificates=20210119 \
git=1:2.30.2-1+deb11u2 \
libpq-dev=13.14-0+deb11u1 \
make=4.3-4.1 \
openssh-client=1:8.4p1-5+deb11u3 \
software-properties-common=0.96.20.2-2.1 \
&& 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==24.0" "setuptools==69.2.0" "wheel==0.43.0" --no-cache-dir


FROM base as dbt-postgres

Check failure on line 28 in docker/Dockerfile

View check run for this annotation

Wiz Inc. (266a8a9c32) / Wiz IaC Scanner

Missing User Instruction

Rule ID: e54afcf9-dc71-484a-8967-d930e3044062 Severity: High Resource: FROM={{base as dbt-postgres}} A user should be specified in the dockerfile, otherwise the image will run as root
Raw output
Expected: The 'Dockerfile' should contain the 'USER' instruction
Found: The 'Dockerfile' does not contain any 'USER' instruction

ARG commit_ref=main

HEALTHCHECK CMD dbt --version || exit 1

WORKDIR /usr/app/dbt/
ENTRYPOINT ["dbt"]

RUN python -m pip install --no-cache-dir "dbt-postgres @ git+https://github.com/dbt-labs/dbt-postgres@${commit_ref}"

Check warning on line 37 in docker/Dockerfile

View check run for this annotation

Wiz Inc. (266a8a9c32) / Wiz IaC Scanner

Unpinned Package Version in Pip Install

Rule ID: 1f0d05d7-8caf-4f04-bc60-332d472de5a9 Severity: Medium Resource: FROM={{base as dbt-postgres}}.{{RUN python -m pip install --no-cache-dir "dbt-postgres @ git+https://github.com/dbt-labs/dbt-postgres@${commit_ref}"}} Package version pinning reduces the range of versions that can be installed, reducing the chances of failure due to unanticipated changes
Raw output
Expected: RUN instruction with 'pip/pip3 install <package>' should use package pinning form 'pip/pip3 install <package>=<version>'
Found: RUN instruction python -m pip install --no-cache-dir "dbt-postgres @ git+https://github.com/dbt-labs/dbt-postgres@main" does not use package pinning form
58 changes: 58 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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.
```shell
docker build --tag <your_image_name> --target dbt-postgres <path/to/dockerfile>
```
---
> **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 image will be populated with the latest version of `dbt-postgres` on `main`.
If you need to use a different version you can specify it by git ref using the `--build-arg` flag:
```shell
docker build --tag <your_image_name> \
--target dbt-postgres \
--build-arg commit_ref=<commit_ref> \
<path/to/dockerfile>
```

### Examples:
To build an image named "my-dbt" that supports Snowflake using the latest releases:
```shell
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:
```shell
cd dbt-core/docker
docker build \
--tag my-other-dbt \
--target dbt-postgres \
--build-arg commit_ref=v1.0.0b1 \
.
```

## 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:
```shell
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.

---
54 changes: 54 additions & 0 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# this image does not get published, it is intended for local development only, see `Makefile` for usage
FROM ubuntu:22.04 as base

# prevent python installation from asking for time zone region
ARG DEBIAN_FRONTEND=noninteractive

# add python repository
RUN apt-get update \

Check notice on line 8 in docker/dev.Dockerfile

View check run for this annotation

Wiz Inc. (266a8a9c32) / Wiz IaC Scanner

APT-GET Not Avoiding Additional Packages

Rule ID: 0cbafd91-7f35-4000-b40a-bebedb7bb5f8 Severity: None Resource: FROM={{ubuntu:22.04 as base}}.{{RUN apt-get update && apt-get install -y software-properties-common=0.99.22.9 && add-apt-repository -y ppa:deadsnakes/ppa && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*}} Check if any apt-get installs don't use '--no-install-recommends' flag to avoid installing additional packages.
Raw output
Expected: 'RUN apt-get update   && apt-get install -y software-properties-common=0.99.22.9   && add-apt-repository -y ppa:deadsnakes/ppa   && apt-get clean   && rm -rf     /var/lib/apt/lists/*     /tmp/*     /var/tmp/*' uses '--no-install-recommends' flag to avoid installing additional packages
Found: 'RUN apt-get update   && apt-get install -y software-properties-common=0.99.22.9   && add-apt-repository -y ppa:deadsnakes/ppa   && apt-get clean   && rm -rf     /var/lib/apt/lists/*     /tmp/*     /var/tmp/*' does not use '--no-install-recommends' flag to avoid installing additional packages
&& apt-get install -y software-properties-common=0.99.22.9 \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*

# install python
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential=12.9ubuntu3 \
git-all=1:2.34.1-1ubuntu1.10 \
libpq-dev=14.11-0ubuntu0.22.04.1 \
python3.8=3.8.19-1+jammy1 \
python3.8-dev=3.8.19-1+jammy1 \
python3.8-distutils=3.8.19-1+jammy1 \
python3.8-venv=3.8.19-1+jammy1 \
python3-pip=22.0.2+dfsg-1ubuntu0.4 \
python3-wheel=0.37.1-2ubuntu0.22.04.1 \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*

# update the default system interpreter to the newly installed version
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

# install python dependencies
RUN python3 -m pip install --upgrade --no-cache-dir "hatch==1.9.1"


FROM base as dbt-postgres-dev

Check failure on line 42 in docker/dev.Dockerfile

View check run for this annotation

Wiz Inc. (266a8a9c32) / Wiz IaC Scanner

Missing User Instruction

Rule ID: e54afcf9-dc71-484a-8967-d930e3044062 Severity: High Resource: FROM={{base as dbt-postgres-dev}} A user should be specified in the dockerfile, otherwise the image will run as root
Raw output
Expected: The 'Dockerfile' should contain the 'USER' instruction
Found: The 'Dockerfile' does not contain any 'USER' instruction

HEALTHCHECK CMD python3 --version || exit 1

# send stdout/stderr to terminal
ENV PYTHONUNBUFFERED=1

# setup mount for local code
WORKDIR /opt/code
VOLUME /opt/code

# create a virtual environment
RUN python3 -m venv /opt/venv
22 changes: 22 additions & 0 deletions docker/test.sh
Original file line number Diff line number Diff line change
@@ -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 commit_ref=v1.0.0b1 \
docker \
&& docker run dbt-postgres-1.0.0b1 --version
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ dependencies = [
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
]
[tool.hatch.envs.default.scripts]
docker-dev = [
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
"docker build -f docker/dev.Dockerfile -t dbt-postgres-dev .",
"docker run --rm -it --name dbt-postgres-dev -v $(pwd):/opt/code dbt-postgres-dev",
]
docker-prod = "docker build -f docker/Dockerfile -t dbt-postgres ."

[tool.hatch.envs.lint]
detached = true
Expand Down
1 change: 1 addition & 0 deletions tests/functional/shared_tests/test_hooks/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file needs to be in its own directory because it uses a `data` directory.
Placing this file in its own directory avoids collisions.
"""

from dbt.tests.adapter.hooks.test_model_hooks import (
BasePrePostModelHooks,
BaseHookRefs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file needs to be in its own directory because it creates a `data` directory at run time.
Placing this file in its own directory avoids collisions.
"""

from dbt.tests.adapter.simple_seed.test_seed import (
BaseBasicSeedTests,
BaseSeedConfigFullRefreshOn,
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_renamed_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ def test_renameable_relation():
identifier="my_table",
type=RelationType.Table,
)
assert relation.renameable_relations == frozenset({
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
})
assert relation.renameable_relations == frozenset(
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
)
Loading