Skip to content
Closed
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
37 changes: 5 additions & 32 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,21 @@ jobs:
strategy:
matrix:
fdb_ver: [6.2.30, 7.1.61]
include:
- fdb_ver: 6.2.30
fdb_lib_url: https://github.com/apple/foundationdb/releases/download/6.2.30/foundationdb-clients_6.2.30-1_amd64.deb

- fdb_ver: 7.1.61
fdb_lib_url: https://github.com/apple/foundationdb/releases/download/7.1.61/foundationdb-clients_7.1.61-1_amd64.deb

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Compute Docker tag
id: docker
run: echo "tag=$(./scripts/docker_tag.sh)" >> $GITHUB_OUTPUT
env:
FDB_VER: ${{ matrix.fdb_ver }}

- name: Build image
uses: docker/bake-action@v5
run: ./build.sh --image build
env:
DOCKER_TAG: ${{ steps.docker.outputs.tag }}
FDB_VER: ${{ matrix.fdb_ver }}
FDB_LIB_URL: ${{ matrix.fdb_lib_url }}
with:
files: bake.hcl
targets: build
load: true
set: |
*.cache-from=type=gha,scope=build-${{ matrix.fdb_ver }}
*.cache-to=type=gha,mode=max,scope=build-${{ matrix.fdb_ver }}

- name: Restore cache
uses: actions/cache@v4
with:
path: ~/.cache/fql
key: go-${{ matrix.fdb_ver }}-${{ hashFiles('go.sum') }}
restore-keys: |
go-${{ matrix.fdb_ver }}-
FENV_FDB_VER: ${{ matrix.fdb_ver }}

- name: Cache FDB image
id: cache-fdb
Expand All @@ -73,7 +46,7 @@ jobs:
- name: Verify
run: ./build.sh --generate --verify
env:
FDB_VER: ${{ matrix.fdb_ver }}
FENV_FDB_VER: ${{ matrix.fdb_ver }}
CACHE_VOLUME: ~/.cache/fql

- name: Fix cache permissions
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "fenv"]
path = fenv
url = https://github.com/janderland/fenv.git
17 changes: 10 additions & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FQL is a query language and alternative client API for FoundationDB written in G
- **Run FQL interactively**: `./build.sh --run [args]`

### Docker-based Development
The build system uses Docker Compose for consistent builds and testing with FoundationDB integration. Always use `./build.sh --verify` instead of running Go commands directly to ensure proper environment setup.
The build system uses fenv (https://github.com/janderland/fenv), a Docker-based FoundationDB development environment, for consistent builds and testing with FoundationDB integration. Always use `./build.sh --verify` instead of running Go commands directly to ensure proper environment setup.

## Architecture

Expand Down Expand Up @@ -78,9 +78,12 @@ Query syntax uses directories (`/path/to/dir`), tuples `("elem1", 2, 0xFF)`, and

## Docker Environment

The build system uses Docker Compose for consistent builds:
- `build.sh` script provides unified interface
- `bake.hcl` defines Docker build configuration
- `compose.yaml` defines runtime services (build, fql, fdb containers)
- Use `--latest` flag for offline development
- FDB container automatically managed for tests
The build system uses fenv for consistent builds:
- `build.sh` script provides unified interface wrapping `fenv/fenv.sh`
- `docker/Dockerfile.builder` extends fenv base image with project-specific build tools (Go, golangci-lint, pandoc)
- Built via `./build.sh --image build` which creates `fenv-ext-fql` image
- `docker/Dockerfile` is a multi-stage build for the final fql runtime image:
- `gobuild` stage uses the pre-built `fenv-ext-fql` builder image to compile the FQL binary
- Final stage creates minimal runtime image with just the binary and FDB client
- `compose.yaml` defines runtime service for running fql image
- fenv automatically manages FDB container for integration testing
76 changes: 0 additions & 76 deletions bake.hcl

This file was deleted.

81 changes: 41 additions & 40 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set -eo pipefail

function print_help {
cat << END
build.sh is a facade for docker compose. It runs a set of
optional tasks in the order specified below. This is the same
script used by CI/CD to build, test, and package FQL.
build.sh is a facade for fenv (FoundationDB development environment).
It runs a set of optional tasks in the order specified below. This is
the same script used by CI/CD to build, test, and package FQL.

If the '--image build' flag is set then the script starts off by
running 'docker build' for the 'fql-build' docker image. The tag
building the extended fenv image with all build tools. The tag
is determined by the git tag/hash and the FDB version. This image
is used to run the 'generate' and 'verify' tasks below.

Expand All @@ -18,7 +18,7 @@ code generated by 'go generate ./...' is up to date.

If the '--verify' flag is set then the script builds, lints, and
tests the codebase. This task interacts with an FDB docker
container which is automatically started.
container which is automatically started by fenv.

If the --docs' flag is set then the documentation HTML will be
generated under the /docs directory.
Expand All @@ -43,10 +43,6 @@ Multiple image names can be specified on the '--image' flag by
separating them with commas.

./build.sh --image build,fql

When building Docker images, the dependencies of the Dockerfile
are specified in 'bake.hcl'. When this file is changed, you'll
need to rebuild the docker images for the changes to take effect.
END
}

Expand Down Expand Up @@ -139,54 +135,59 @@ while [[ $# -gt 0 ]]; do
done


# Build variables required by the docker compose command.

BUILD_TASKS=()

if [[ -n "$VERIFY_GENERATION" ]]; then
BUILD_TASKS+=('./scripts/verify_generation.sh')
fi

if [[ -n "$VERIFY_CODEBASE" ]]; then
BUILD_TASKS+=('./scripts/setup_database.sh')
BUILD_TASKS+=("./scripts/verify_codebase.sh")
fi
# Build variables for fenv and docker commands.

if [[ -n "$GENERATE_DOCS" ]]; then
BUILD_TASKS+=('./scripts/generate_docs.sh')
fi
# Set fenv environment variables
export FENV_FDB_VER="${FENV_FDB_VER:-6.2.30}"
export FENV_PROJECT_NAME="fql"

BUILD_COMMAND="$(join_array ' && ' "${BUILD_TASKS[@]}")"
echo "BUILD_COMMAND=${BUILD_COMMAND}"
export BUILD_COMMAND

FQL_COMMAND=${FQL_ARGS[*]}
echo "FQL_COMMAND=${FQL_COMMAND}"
export FQL_COMMAND

DOCKER_TAG="$(./scripts/docker_tag.sh)"
DOCKER_TAG="$(./fenv/docker_tag.sh)"
echo "DOCKER_TAG=${DOCKER_TAG}"
export DOCKER_TAG

FDB_DOCKER_IMAGE="foundationdb/foundationdb:${FDB_VER:-6.2.30}"
echo "FDB_DOCKER_IMAGE=${FDB_DOCKER_IMAGE}"
export FDB_DOCKER_IMAGE
# fenv command with common flags
FENV_CMD=(./fenv/fenv.sh --docker ./docker/Dockerfile.builder)


# Run the requested commands.

# Build the extended fenv image if requested
if [[ -n "$IMAGE_BUILD" ]]; then
(set -x; docker buildx bake -f bake.hcl --load build)
echo "Building extended fenv image..."
(set -x; "${FENV_CMD[@]}" --build)
fi

# Execute build tasks (generate, verify, docs) using fenv
if [[ -n "$VERIFY_GENERATION" ]]; then
echo "Verifying code generation..."
(set -x; "${FENV_CMD[@]}" --exec ./scripts/verify_generation.sh)
fi

if [[ -n "$BUILD_COMMAND" ]]; then
(set -x; docker compose run --rm build /bin/sh -c "$BUILD_COMMAND")
if [[ -n "$VERIFY_CODEBASE" ]]; then
echo "Verifying codebase..."
(set -x; "${FENV_CMD[@]}" --exec ./scripts/verify_codebase.sh)
fi

if [[ -n "$GENERATE_DOCS" ]]; then
echo "Generating documentation..."
(set -x; "${FENV_CMD[@]}" --exec ./scripts/generate_docs.sh)
fi

# Build the final fql image if requested
if [[ -n "$IMAGE_FQL" ]]; then
(set -x; docker buildx bake -f bake.hcl --load fql)
echo "Building fql runtime image..."
(set -x; docker build \
-f ./docker/Dockerfile \
-t "docker.io/janderland/fql:${DOCKER_TAG}" \
--build-arg "FQL_VER=${DOCKER_TAG}" \
--build-arg "FENV_FDB_VER=${FENV_FDB_VER}" \
--build-arg "FENV_EXT_DOCKER_TAG=${DOCKER_TAG}" \
.)
fi

# Run fql interactively if requested
if [[ -n "$RUN_FQL" ]]; then
echo "Running fql with args: ${FQL_ARGS[*]}"
export FDB_DOCKER_IMAGE="foundationdb/foundationdb:${FENV_FDB_VER}"
(set -x; docker compose run --rm fql 'docker:docker@{fdb}:4500' "${FQL_ARGS[@]}")
fi
78 changes: 13 additions & 65 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,7 @@
# 'builder' includes all build & testing dependencies.
FROM debian:12 AS builder

RUN apt-get update &&\
apt-get install --no-install-recommends -y \
build-essential=12.9 \
ca-certificates=20* \
git=1:2.39.* \
curl=7.88.* &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/*

# The FDB installer is not deleted so it can be used to
# install the library in the final stage at the end of
# this file.
ARG FDB_LIB_URL
RUN curl -Lo /fdb.deb $FDB_LIB_URL &&\
dpkg -i /fdb.deb

ARG GO_URL
RUN curl -Lo /go.tar.gz $GO_URL &&\
tar -C /usr/local -xzf /go.tar.gz &&\
rm /go.tar.gz
ENV PATH="/root/go/bin:/usr/local/go/bin:${PATH}"
ENV GOCACHE="/cache/gocache"
ENV GOMODCACHE="/cache/gomod"

ARG GOLANGCI_LINT_URL="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
ARG GOLANGCI_LINT_VER
RUN curl -Lo /golint.sh $GOLANGCI_LINT_URL &&\
sh /golint.sh -b "$(go env GOPATH)/bin" $GOLANGCI_LINT_VER &&\
rm /golint.sh
ENV GOLANGCI_LINT_CACHE="/cache/golangci-lint"

ARG SHELLCHECK_URL
RUN curl -Lo /shellcheck.tar.xz $SHELLCHECK_URL &&\
tar -xf /shellcheck.tar.xz &&\
mv /shellcheck-*/shellcheck /usr/local/bin &&\
rm -r /shellcheck.tar.xz /shellcheck-*

ARG HADOLINT_URL
RUN curl -Lo /usr/local/bin/hadolint $HADOLINT_URL &&\
chmod +x /usr/local/bin/hadolint

ARG JQ_URL
RUN curl -Lo /usr/local/bin/jq $JQ_URL &&\
chmod +x /usr/local/bin/jq

ARG PANDOC_URL
RUN curl -Lo /pandoc.deb $PANDOC_URL &&\
dpkg -i /pandoc.deb &&\
rm /pandoc.deb

# Configure git so it allows any user to run git commands
# on the /fql directory. This allows the user which runs
# CI to be different from the user which built the Docker
# image.
RUN git config --global --add safe.directory /fql


# 'gobuild' executes 'go build'.
FROM builder AS gobuild
# 'gobuild' stage compiles the FQL binary using the pre-built builder image from fenv.
# The builder image (fenv-ext-fql) is built separately via ./build.sh --image build
ARG FENV_EXT_DOCKER_TAG
FROM fenv-ext-fql:${FENV_EXT_DOCKER_TAG} AS gobuild

COPY . /src
WORKDIR /src
Expand All @@ -68,11 +10,17 @@ ARG FQL_VER
RUN go build -o /fql -ldflags="-X 'github.com/janderland/fql/internal/app.Version=${FQL_VER}'"


# The final stage builds the 'fql' image.
# The final stage builds the minimal 'fql' runtime image.
FROM debian:12

COPY --from=gobuild /fdb.deb /fdb.deb
RUN dpkg -i ./fdb.deb &&\
RUN apt-get update && \
apt-get install --no-install-recommends -y curl=7.88.* && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ARG FENV_FDB_VER
RUN curl -fsSL "https://github.com/apple/foundationdb/releases/download/${FENV_FDB_VER}/foundationdb-clients_${FENV_FDB_VER}-1_amd64.deb" -o /fdb.deb && \
dpkg -i /fdb.deb && \
rm /fdb.deb

ENV TERM="xterm-256color"
Expand Down
Loading