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
65 changes: 0 additions & 65 deletions .github/workflows/docker_image_smoketest.yml

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/ensure_sync_service_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Docker Image for sync-service

on:
workflow_call:
inputs:
tag:
required: false
type: string
outputs:
image:
description: 'Full image ref'
value: ${{ jobs.build_image.outputs.image }}

jobs:
build_image:
runs-on: ubuntu-latest

# Make sure that all workflows calling this with the same tag will queue here.
# Only the first workflow to reach this point will trigger a new image build, the other
# workflows will use it once it's been built and pushed.
concurrency:
group: sync-service-ci-image-${{ inputs.tag }}
cancel-in-progress: false

permissions:
contents: read
packages: write

outputs:
image: ${{ steps.out.outputs.image }}

steps:
- uses: actions/checkout@v4

- name: Set image ref
id: vars
run: |
echo "IMAGE=ghcr.io/${{ github.repository }}/sync-service" >> $GITHUB_ENV
echo "TAG=${{ inputs.tag }}" >> $GITHUB_ENV

- name: Login to GHCR (private)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get the latest commit SHA that has touched files in either packages/electric-telemetry or packages/sync-service
if: ${{ !env.TAG }}
run: |
echo "TAG=$(
git log -1 --format='%H' -- packages/electric-telemetry/ packages/sync-service/
)" >> $GITHUB_ENV

- name: Check if image tag already exists
id: exists
run: |
if docker manifest inspect "${IMAGE}:${TAG}" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Set up buildx for advanced Docker caching
uses: docker/setup-buildx-action@v3

- name: Build and push if missing
if: steps.exists.outputs.exists != 'true'
uses: docker/build-push-action@v6
with:
context: packages/sync-service
build-contexts: |
electric-telemetry=packages/electric-telemetry
push: true
tags: ${{ env.IMAGE }}:${{ env.TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Output image ref
id: out
run: |
echo "image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
72 changes: 12 additions & 60 deletions .github/workflows/ts_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

permissions:
contents: read
packages: write

jobs:
list_ts_packages:
Expand All @@ -26,6 +27,7 @@ jobs:
- uses: actions/checkout@v4
- run: echo "directories=`find packages/ -mindepth 1 -maxdepth 1 -type d -exec test -e '{}'/tsconfig.json \; -print | jq -R -s -c 'split("\n")[:-1]'`" >> $GITHUB_OUTPUT
id: list_ts_packages

list_examples:
name: List examples
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,14 +60,13 @@ jobs:
- run: pnpm -r --filter "$(jq '.name' -r package.json)^..." build
- run: pnpm run typecheck

ensure_sync_service_image:
uses: ./.github/workflows/ensure_sync_service_image.yml

build_and_test_packages:
name: 'Test ${{ matrix.package_dir }} w/ sync-service'
needs: [list_ts_packages]
needs: [list_ts_packages, ensure_sync_service_image]
runs-on: ubuntu-latest
# There is currently a buggy TS test that causes the job for typescript-client to get stuck
# for 6 hours on end.
# And it's a good practice in general to limit the test runtime and investigate at the
# point when it starts exceeding the limit.
timeout-minutes: 10
strategy:
fail-fast: false
Expand All @@ -75,17 +76,10 @@ jobs:
run:
working-directory: ${{ matrix.package_dir }}
env:
ELECTRIC_DATABASE_ID: ci_test_tenant
MIX_ENV: dev
MIX_OS_DEPS_COMPILE_PARTITION_COUNT: 4
ELECTRIC_IMAGE: ${{ needs.ensure_sync_service_image.outputs.image }}
steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: '.tool-versions'

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
Expand All @@ -96,56 +90,14 @@ jobs:
- name: Install Node dependencies
run: pnpm install --frozen-lockfile

- name: Cache sync-service dependencies
uses: actions/cache@v4
with:
path: packages/sync-service/deps
key: "${{ runner.os }}-sync-service-deps-${{ env.MIX_ENV }}-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ env.MIX_ENV }}-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-${{ env.MIX_ENV }}
${{ runner.os }}-sync-service-deps

- name: Cache sync-service compiled code
uses: actions/cache@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: "${{ runner.os }}-sync-service-build-${{ env.MIX_ENV }}-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-build-${{ env.MIX_ENV }}-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-build-${{ env.MIX_ENV }}
${{ runner.os }}-sync-service-build

- name: Install sync-service dependencies
working-directory: packages/sync-service
run: mix do deps.get + deps.compile

- name: Compile sync-service
working-directory: packages/sync-service
run: mix compile

- uses: JarvusInnovations/background-action@v1
name: Bootstrap System Under Test (SUT)
with:
run: |
mix start_dev
ELECTRIC_INSECURE=true mix run --no-halt &

wait-on: |
http-get://localhost:3000/v1/health?database_id=${{ env.ELECTRIC_DATABASE_ID }}

tail: true
log-output-resume: stderr
wait-for: 1m
log-output: true
log-output-if: failure
working-directory: packages/sync-service

- name: Build Node dependencies, if any
run: pnpm -r --filter "$(jq '.name' -r package.json)^..." build

- name: Run Postgres, Electric and nginx for the subsequent test suite
working-directory: packages/sync-service/dev
run: |
docker compose -f docker-compose.yml -f docker-compose-electric.yml up --wait postgres electric nginx

- name: Run tests with coverage
run: pnpm run coverage --run

Expand Down
16 changes: 16 additions & 0 deletions packages/sync-service/dev/docker-compose-electric.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
electric:
image: $ELECTRIC_IMAGE
env_file: ../.env.dev
environment:
DATABASE_URL: 'postgresql://postgres:password@postgres/electric?sslmode=disable'
ports:
- 3000:3000
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:3000/v1/health"]
interval: 5s
timeout: 5s
retries: 10
depends_on:
postgres:
condition: service_healthy
13 changes: 7 additions & 6 deletions packages/sync-service/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ services:
tmpfs:
- /var/lib/postgresql
- /tmp
entrypoint:
- docker-entrypoint.sh
command:
- -c
- config_file=/etc/postgresql.conf
healthcheck:
test: ["CMD", "pg_isready"]
interval: 5s
timeout: 5s
retries: 5
postgres2:
image: postgres:18-alpine
environment:
Expand All @@ -36,8 +40,7 @@ services:
tmpfs:
- /var/lib/postgresql
- /tmp
entrypoint:
- docker-entrypoint.sh
command:
- -c
- config_file=/etc/postgresql.conf
pgbouncer:
Expand All @@ -62,5 +65,3 @@ services:
- ./nginx.conf:/etc/nginx/nginx.conf
extra_hosts:
- 'host.docker.internal:host-gateway'
depends_on:
- postgres