Skip to content
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.git
.idea
coverage
18 changes: 10 additions & 8 deletions .github/workflows/build-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ jobs:
with:
fetch-depth: 0
fetch-tags: true
- name: Install Deno
uses: denoland/setup-deno@v2
- name: Install Node.js
uses: actions/setup-node@v6
with:
cache-hash: ${{ hashFiles('**/deno.lock') }}
deno-version: v2.x
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Export version
run: |
echo "DENO_VERSION=$(jq -r '.version' deno.json)" >> $GITHUB_ENV
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Typecheck
run: deno check
run: npx tsc --noEmit

- name: Install PostgreSQL 17 client
run: |
Expand All @@ -33,7 +35,7 @@ jobs:
sudo apt install -y postgresql-client-17

- name: Run tests
run: deno run test
run: npx vitest run
env:
PG_DUMP_BINARY: /usr/lib/postgresql/17/bin/pg_dump
PG_RESTORE_BINARY: /usr/lib/postgresql/17/bin/pg_restore
Expand All @@ -42,6 +44,6 @@ jobs:
uses: softprops/action-gh-release@v2
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
tag_name: v${{ env.DENO_VERSION }}
tag_name: v${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set sync_version from deno.json
- name: Set sync_version from package.json
run: |
sync_version=$(jq -r '.version' deno.json)
sync_version=$(jq -r '.version' package.json)
echo "sync_version=${sync_version}" >> $GITHUB_ENV
- name: Build and push @query-doctor/analyzer
id: build
Expand Down
76 changes: 31 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
ARG ALPINE_VERSION=3.22
ARG DENO_VERSION=2.4.5
ARG PG_IMAGE=ghcr.io/query-doctor/postgres:pg14-timescale-2.16

FROM denoland/deno:alpine-${DENO_VERSION} AS deno
ARG PG_IMAGE=pg14-timescale-2.16
FROM alpine:${ALPINE_VERSION} AS pgbadger-builder

RUN apk add --no-cache \
perl \
curl \
make \
postgresql-client \
git
make

ARG PGBADGER_VERSION=13.2
WORKDIR /tmp
Expand All @@ -22,52 +18,41 @@ RUN curl -L https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.
make install && \
rm -rf /tmp/pgbadger*

FROM gcr.io/distroless/cc-debian12:latest AS cc

FROM alpine:${ALPINE_VERSION} AS sym

COPY --from=cc --chmod=755 --chown=root:root /lib/*-linux-gnu/ld-linux-* /usr/local/lib/
RUN mkdir -p -m 755 /tmp/lib
RUN ln -s /usr/local/lib/ld-linux-* /tmp/lib/

FROM denoland/deno:alpine-${DENO_VERSION} AS build

COPY deno.json deno.lock* ./
RUN deno install --frozen-lockfile
# Build the application
FROM node:24-alpine AS build

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm ci --omit=dev

RUN deno compile \
--allow-run \
--allow-read \
--allow-write \
--allow-env \
--allow-net \
--allow-sys \
-o /app/analyzer \
src/main.ts

FROM alpine:${ALPINE_VERSION}
# Final image
ARG PG_IMAGE
ENV LD_LIBRARY_PATH="/usr/local/lib"
FROM node:24-alpine

RUN apk add -uU --no-cache \
readline \
zlib \
bash \
su-exec \
openssl \
ossp-uuid \
postgresql-client \
krb5
krb5 \
postgresql17-client \
perl

COPY --from=build --chmod=755 --chown=root:root /app/analyzer /app/analyzer
COPY --from=cc --chmod=755 --chown=root:root /lib/*-linux-gnu/* /usr/local/lib/
COPY --from=sym --chmod=755 --chown=root:root /tmp/lib /lib
COPY --from=sym --chmod=755 --chown=root:root /tmp/lib /lib64
# Copy pgBadger
COPY --from=pgbadger-builder /usr/local/bin/pgbadger /usr/local/bin/pgbadger

COPY --from=ghcr.io/query-doctor/postgres:pg14-timescale-2.16 /usr/local/pgsql /usr/local/pgsql

# Copy application
COPY --from=build /app/dist /app/dist
COPY --from=build /app/node_modules /app/node_modules

# Setup postgres user and directories
RUN mkdir -p /var/lib/postgresql/data \
&& chown -R postgres:postgres /var/lib/postgresql \
&& chown -R postgres:postgres /usr/local/pgsql \
Expand All @@ -84,16 +69,17 @@ RUN sed -i 's|nobody:/|nobody:/home|' /etc/passwd && chown nobody:nobody /home

ENV POSTGRES_URL=postgresql://postgres@localhost/postgres?host=/tmp

RUN su-exec postgres initdb -D $PGDATA || true && \
echo "shared_preload_libraries = 'timescaledb,pg_stat_statements'" >> $PGDATA/postgresql.conf && \
echo "listen_addresses = ''" >> $PGDATA/postgresql.conf && \
echo "unix_socket_directories = '/tmp'" >> $PGDATA/postgresql.conf
COPY ./docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh


USER postgres

RUN initdb -D "$PGDATA"

# We don't expose 5432 because
# 1. We use a unix socket
# 2. The external user should never have to interface with the internal postgres service
EXPOSE 2345

CMD ["/bin/bash", "-c", "\
pg_ctl -D $PGDATA -l $PGDATA/logfile start || (cat $PGDATA/logfile && exit 1) && \
until pg_isready -h /tmp; do sleep 0.5; done && \
/app/analyzer"]
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
17 changes: 10 additions & 7 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ branding:
runs:
using: "composite"
steps:
# Setup Deno environment
- name: Install Deno
uses: denoland/setup-deno@v2
- name: Install Node.js
uses: actions/setup-node@v6
with:
cache: true
deno-version: v2.x
node-version: 24
cache: npm

- name: Install dependencies
shell: bash
run: npm ci

# Cache pgBadger build
- name: Cache pgBadger
Expand Down Expand Up @@ -48,10 +51,10 @@ runs:
sudo make install # Use sudo to install globally
cd ${{ github.action_path }} # Return to action directory

# Run the compiled application
# Run the application
- name: Run Analyzer
shell: bash
run: deno run start
run: npm run start
env:
PG_DUMP_BINARY: /usr/bin/pg_dump
CI: "true"
Expand Down
51 changes: 0 additions & 51 deletions deno.json

This file was deleted.

Loading