Skip to content

Commit

Permalink
Build docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Aug 9, 2024
1 parent 863e715 commit 234dc14
Show file tree
Hide file tree
Showing 12 changed files with 4,639 additions and 27 deletions.
38 changes: 37 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches: [main]

permissions:
id-token: write
contents: read

jobs:
test-core:
name: Test core
Expand Down Expand Up @@ -37,4 +41,36 @@ jobs:

- name: Run ESLint
run: pnpm lint
working-directory: ./core
working-directory: ./core

build-local:
name: Build local docker image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GH_ASSUME_ROLE }}
role-session-name: github-actions-bemi-local
aws-region: us-east-1

- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build, tag, and push image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: u4i4s8t6
REPOSITORY: bemi-local
IMAGE_TAG: latest
run: |
cd worker
mv ../core ./core
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
74 changes: 56 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ Bemi automatically tracks database changes ensuring 100% reliability and a compr

- [Highlights](#highlights)
- [Use cases](#use-cases)
- [System dependencies](#system-dependencies)
- [Quickstart](#quickstart)
- [Running with Docker](#running-with-docker)
- [Running with Devbox](#running-with-devbox)
- [Running with Natively](#running-with-natively)
- [Contextualizing data changes](#contextualizing-data-changes)
- [Architecture](#architecture)
- [Testing](#testing)
- [License](#license)
Expand All @@ -54,51 +59,82 @@ There's a wide range of use cases that Bemi is built for! The tech was initially
- **Testing:** Rollback or roll-forward to different application test states.
- **Analyzing Trends:** Gain insights into historical trends and changes for informed decision-making.

## Quickstart

### System dependencies
## System dependencies

- [Node.js](https://github.com/nodejs/node)
- [NATS server](https://github.com/nats-io/nats-server)

You can install these system dependencies manually or use [Devbox](https://github.com/jetpack-io/devbox) that relies on
[Nix Packages](https://github.com/NixOS/nixpkgs) for providing isolated shells without containerization.

And of course, you need a PostgreSQL database that you want to connect to to track data changes. Make sure your database has `SHOW wal_level;` returning `logical`. Otherwise, you need to run the following SQL command and restart your PostgreSQL server:

```sql
ALTER SYSTEM SET wal_level = logical;
```

### Installation
## Quickstart

### Running with Docker

After installing all system dependencies, install all project dependencies with Node.js:
Run a Docker container that connects to your local PostgreSQL database:

```sh
make worker-setup && cd worker && npm install
docker run \
-e DB_HOST=host.docker.internal \
-e DB_PORT=5434 \
-e DB_NAME=bemi_dev_source \
-e DB_USER=postgres \
-e DB_PASSWORD=postgres \
public.ecr.aws/u4i4s8t6/bemi-local:latest
```

`DB_HOST` pointing to `host.docker.internal` allows accessing `127.0.0.1` on your host machine if you run PostgreSQL outside Docker.

Now try making some database changes like:

```sql
UPDATE _bemi_migrations SET executed_at = NOW() WHERE id = 1;
```

Alternatively, you can use Devbox instead and run a single command that will also install Node.js with pnpm and NATS server:
This will add a new record in the `changes` table within the same database after a few seconds.

### Running with Devbox

You can install all system dependencies manually or use [Devbox](https://github.com/jetpack-io/devbox) that relies on
[Nix Packages](https://github.com/NixOS/nixpkgs) for providing isolated shells without containerization.
Run a single command that will install Node.js with pnpm and NATS server:

```sh
make worker-install
```

### Data change tracking

Set environment variables specifying connection settings for a PostgreSQL database you want to track:
Set environment variables specifying connection settings for a PostgreSQL database you want to track and run a worker:

```sh
export DB_HOST=127.0.0.1 DB_PORT=5432 DB_NAME=postgres DB_USER=postgres DB_PASSWORD=postgres
make worker-up
```

Now try making some database changes like:

```sql
UPDATE _bemi_migrations SET executed_at = NOW() WHERE id = 1;
```

Run a worker as a single process with directly installed Node.js:
This will add a new record in the `changes` table within the same database after a few seconds.

### Running natively

After installing all system dependencies, install all project dependencies with Node.js:

```sh
cd worker && npm concurrently -- "npm:up:*"
make worker-setup && cd worker && npm install
```

# Alternatively, with Devbox
make worker-up
Set environment variables specifying connection settings for a PostgreSQL database you want to track run a worker as a single process with directly installed Node.js:


```sh
export DB_HOST=127.0.0.1 DB_PORT=5432 DB_NAME=postgres DB_USER=postgres DB_PASSWORD=postgres
npm concurrently -- "npm:up:*"
```

Now try making some database changes like:
Expand All @@ -109,7 +145,9 @@ UPDATE _bemi_migrations SET executed_at = NOW() WHERE id = 1;

This will add a new record in the `changes` table within the same database after a few seconds.

To optionally automatically enhance these low-level database changes with application-specific context (e.g., user ID, API endpoint, etc.), check out our compatible [ORM packages](https://docs.bemi.io/#supported-orms).
## Contextualizing data changes

Optionally, to automatically enhance these low-level database changes with application-specific context (e.g., user ID, API endpoint, etc.), check out our compatible [ORM packages](https://docs.bemi.io/#supported-orms).

## Architecture

Expand Down
Loading

0 comments on commit 234dc14

Please sign in to comment.