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 Dockerfile and build image flow #567

Merged
merged 17 commits into from
May 28, 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
29 changes: 29 additions & 0 deletions .github/workflows/build-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,32 @@ jobs:
--tag ghcr.io/canner/wren-engine:nightly \
--push -f ./Dockerfile \
--build-arg "WREN_VERSION=${WREN_VERSION}" .
build-ibis-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/canner/wren-engine-ibis
tags: |
type=sha
type=raw,value=nightly
Comment on lines +54 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time to know this action to put the image tags. it's really concise!

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./ibis-server
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
58 changes: 48 additions & 10 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ on:
description: Docker image tag name (Optional)

jobs:
prepare-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare tag name
id: prepare_tag
run: |
if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then
tag_name=${{ github.event.inputs.docker_image_tag_name }}
else
tag_name=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')-$(git log -1 --pretty=%h)
fi
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
outputs:
tag_name: ${{ steps.prepare_tag.outputs.tag_name }}
build-image:
needs: prepare-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -31,23 +47,45 @@ jobs:
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Prepare tag name
id: prepare_tag
run: |
if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then
tag_name=${{ github.event.inputs.docker_image_tag_name }}
else
tag_name=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')-$(git log -1 --pretty=%h)
fi
echo ::set-output name=tag_name::$tag_name
- name: Build Docker image
env:
TAG_NAME: ${{ needs.prepare-tag.outputs.tag_name }}
run: |
WREN_VERSION=$(./mvnw --quiet help:evaluate -Dexpression=project.version -DforceStdout)
cd ./docker
cp ../wren-server/target/wren-server-${WREN_VERSION}-executable.jar ./
cp -r ../wren-sqlglot-server/ ./
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-engine:${{ steps.prepare_tag.outputs.tag_name }} \
--tag ghcr.io/canner/wren-engine:$TAG_NAME \
--push -f ./Dockerfile \
--build-arg "WREN_VERSION=${WREN_VERSION}" .
build-ibis-image:
needs: prepare-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/canner/wren-engine-ibis
tags: |
type=raw,value=${{ needs.prepare-tag.outputs.tag_name }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./ibis-server
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
64 changes: 63 additions & 1 deletion .github/workflows/stable-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
description: Specific version number (Optional). Default will be the current version plus 0.0.1.

jobs:
prepare-release:
stable-release-wren-engine:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -62,3 +62,65 @@ jobs:
--tag ghcr.io/canner/wren-engine:latest \
--push -f ./Dockerfile \
--build-arg "WREN_VERSION=${WREN_VERSION}" .
prepare-ibis-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GHCR_TOKEN }}
- name: Set up Git
run: |
git config --global user.email "dev@cannerdata.com"
git config --global user.name "stable-release-bot"
- uses: actions/setup-python@v5
with:
python-version-file: ./ibis-server/pyproject.toml
- uses: abatilo/actions-poetry@v3
with:
poetry-version: 1.7.1
- name: Prepare next version
id: next_version
working-directory: ibis-server
run: |
if [ -n "${{ github.event.inputs.specific_version }}" ]; then
poetry version --next-phase ${{ github.event.inputs.specific_version }}
else
poetry version patch
fi
git add pyproject.toml
git commit -m "Upgrade ibis version to $version"
git push
version=$(poetry version | awk '{print $2}')
echo "value=$version" >> $GITHUB_OUTPUT
outputs:
next_version: ${{ steps.next_version.outputs.value }}
stable-release-ibis:
needs: prepare-ibis-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/canner/wren-engine-ibis
tags: |
type=raw,value=${{ needs.prepare-ibis-version.outputs.next_version }}
type=raw,value=latest
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./ibis-server
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
41 changes: 41 additions & 0 deletions ibis-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM python:3.11-buster as builder

# libpq-dev is required for psycopg2
RUN apt-get update && apt-get -y install libpq-dev

# python
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
# poetry
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1

RUN pip install poetry==1.7.1

WORKDIR /app

COPY pyproject.toml ./

RUN poetry install --without dev

FROM python:3.11-slim-buster as runtime

# libpq-dev is required for psycopg2
RUN apt-get update \
&& apt-get -y install libpq-dev \
&& rm -rf /var/lib/apt/lists/*

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY app app

EXPOSE 8000

ENTRYPOINT fastapi run
6 changes: 6 additions & 0 deletions ibis-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ dev:

test:
poetry run pytest

docker-build:
docker image build . -t wren-engine-ibis

docker-run:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
docker-run:
dev-docker-run:

How about add a dev prefix? I guess someone maybe confuse on which version would be started by this command. The image on repo? or The local build.
I guess this one will start the local one, right?

docker run -it --rm -p 8000:8000 --env-file .env wren-engine-ibis
49 changes: 46 additions & 3 deletions ibis-server/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
# Ibis server

## Environment Setup
## Quick Start
### Running on Docker
Pull the image from the GitHub Container Registry
```bash
docker pull ghcr.io/canner/wren-engine-ibis:latest
```
Create `.env` file and fill in the environment variables (see [Environment Variables](#Environment-Variables)) \
```bash
vim .env
```
Run the container
```bash
docker run --env-file .env -p 8000:8000 ghcr.io/canner/wren-engine-ibis:latest
```
### Running on Local
Requirements:
- Python 3.11
- [poetry](https://github.com/python-poetry/poetry) 1.7.1

Clone the repository and navigate to the ibis directory
```bash
git clone git@github.com:Canner/wren-engine.git
cd ibis-server
```
Create `.env` file and fill in the environment variables (see [Environment Variables](#Environment-Variables))
```bash
vim .env
```
Install the dependencies
```bash
make install
```
Run the server
```bash
make run
```

## Developer Guide

### Environment Setup
- Python 3.11
- Install `poetry` with version 1.7.1: `curl -sSL https://install.python-poetry.org | python3 - --version 1.7.1`
- Execute `make install` to install the dependencies
- Execute `make test` to run the tests
- Create `.env` file and fill in the environment variables

## Environment Variables
### Environment Variables
- `WREN_ENGINE_ENDPOINT`: The endpoint of the Wren engine

## Start the server
### Start the server
- Execute `make run` to start the server
- Execute `make dev` to start the server in development mode. It will auto-reload after the code is edited.
- Default port is `8000`, you can change it by `make run PORT=8001` or `make dev PORT=8001`

### Docker
- Build the image: `make docker-build`
- Run the container: `make docker-run`
4 changes: 2 additions & 2 deletions ibis-server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ibis-server"
version = "0.1.0"
version = "0.4.5"
description = ""
authors = ["Canner <dev@cannerdata.com>"]
readme = "README.md"
Expand All @@ -15,7 +15,7 @@ ibis-framework = {extras = ["bigquery", "postgres", "snowflake"], version = "9.0
google-auth = "2.29.0"
httpx = "0.27.0"
python-dotenv = "1.0.1"
orjson = "2.0.1"
orjson = "3.10.3"

[tool.poetry.group.dev.dependencies]
pytest = "8.2.0"
Expand Down