Skip to content
Open
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
62 changes: 21 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG ALPINE_VERSION=3.22
ARG DENO_VERSION=2.4.5
FROM alpine:${ALPINE_VERSION} AS pg-builder

# Install build dependencies
Expand Down Expand Up @@ -49,53 +48,32 @@ RUN cd build && make -j$(nproc)
RUN cd build && make install

# Adapted from https://github.com/dojyorin/deno_docker_image/blob/master/src/alpine.dockerfile
FROM denoland/deno:alpine-${DENO_VERSION} AS deno
# Build pgBadger
FROM alpine:${ALPINE_VERSION} AS pgbadger-builder

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

# Download, build, and install pgBadger
ARG PGBADGER_VERSION=13.2
WORKDIR /tmp

RUN curl -L https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.gz | tar -xzf - && \
cd pgbadger-${PGBADGER_VERSION} && \
perl Makefile.PL && \
make && \
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}
ENV LD_LIBRARY_PATH="/usr/local/lib"
# Final image
FROM node:24-alpine

RUN apk add -uU --no-cache \
postgresql-client \
Expand All @@ -104,17 +82,19 @@ RUN apk add -uU --no-cache \
bash \
su-exec \
openssl \
krb5
krb5 \
perl

COPY --from=deno --chmod=755 --chown=root:root /usr/bin/pg_dump /usr/bin/pg_dump
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 PostgreSQL installation from builder
COPY --from=pg-builder /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 \
Expand Down Expand Up @@ -142,4 +122,4 @@ CMD ["/bin/bash", "-c", "\
echo \"unix_socket_directories = '/tmp'\" >> $PGDATA/postgresql.conf && \
su-exec postgres pg_ctl -D $PGDATA -l $PGDATA/logfile start || (cat $PGDATA/logfile && exit 1) && \
until su-exec postgres pg_isready -h /tmp; do sleep 0.5; done && \
/app/analyzer"]
node /app/dist/main.mjs"]
12 changes: 5 additions & 7 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine
FROM node:24-alpine

# Install pgbadger dependencies
RUN apk add --no-cache \
Expand All @@ -18,14 +18,12 @@ RUN wget https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.gz
make install && \
rm -rf /tmp/pgbadger*

# RUN curl -L https://github.com/supabase-community/postgres-language-server/releases/download/<version>/postgrestools_aarch64-apple-darwin -o postgrestools
# RUN chmod +x postgrestools

WORKDIR /app

# Copy dependency files
COPY deno.json deno.lock* ./
COPY package.json package-lock.json ./

RUN npm ci

RUN deno install --frozen-lockfile
# Development command
CMD ["deno", "run", "dev"]
CMD ["npm", "run", "start:dev"]
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