Skip to content

Commit

Permalink
feat: create a minimal docker image and github workflow for building …
Browse files Browse the repository at this point in the history
…it when pushed to master branch (#60)

* feat: create a minimal docker image and github workflow for building it when pushed to master branch

* fix: add --platform target

* feat: add static build for graphql binary

* feat: added Docker section to README and a simple docker-compose.yml that starts all indexing

* fix: add link to ghcr package repo

* fix: remove postgres volume

* fix: only build docker image for merges into master from a release

* fix: Dockerfile

* fix: build docker image only for merges from release/** branches to master

* feat: add docker usage instructions to docs

* feat: add docs for creating a new project with docker

* feat: build dynamically linked binaries with debian base image
  • Loading branch information
crebsy committed Jul 30, 2024
1 parent 8f46387 commit 4c4089a
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
Dockerfile
.env
56 changes: 56 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build & publish docker image

on:
pull_request:
types:
- closed
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=sha,format=long
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM --platform=linux/amd64 rust:1.79-slim-bookworm as builder
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
RUN apt update && apt install -y libssl-dev binutils libc-dev libstdc++6 pkg-config

WORKDIR /app
COPY . .
RUN cargo build --release
RUN strip /app/target/release/rindexer_cli

FROM --platform=linux/amd64 node:lts-bookworm as node-builder
RUN apt update && apt install -y ca-certificates
WORKDIR /app
COPY . .
RUN cd /app/graphql && npm i && npm run build-linux

FROM --platform=linux/amd64 debian:bookworm-slim
RUN apt update \
&& apt install -y libssl-dev libc-dev libstdc++6 ca-certificates lsof \
&& apt-get autoremove --yes \
&& apt-get clean --yes \
&& rm -rf /var/lib/apt/lists/*

COPY --from=node-builder /app/core/resources/rindexer-graphql-linux /app/resources/rindexer-graphql-linux
COPY --from=builder /app/target/release/rindexer_cli /app/rindexer

ENTRYPOINT ["/app/rindexer"]
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ Options:
We have full documentation https://rindexer.xyz/docs/introduction/installation which goes into more detail on how to use
rindexer and all the commands available to you.

## Docker

There's a pre-built docker image which can be used to run `rindexer` inside your dockerized infra:

[`ghcr.io/joshstevens19/rindexer`](https://github.com/users/joshstevens19/packages/container/package/rindexer)

### Create new project
To create a new `no-code` project in your current directory, you can run the following:

`docker run -it -v $PWD:/app/project_path ghcr.io/joshstevens19/rindexer new -p /app/project_path no-code`

### Use with existing project
To use it with an existing project and a running postgres instance you can simply invoke:

```
export PROJECT_PATH=/path/to/your/project
export DATABASE_URL="postgresql://user:pass@postgres/db"
docker-compose up -d
```

This will start all local indexing and if you have enabled the graphql endpoint, it will become exposed under:

http://localhost:3001


## What can I use rindexer for?

- Hackathons: spin up a quick indexer to index events for your dApp with an API without any code needed
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
networks:
default:
name: rindexer_default

services:
rindexer:
image: ghcr.io/joshstevens19/rindexer
platform: linux/amd64
command: |
start -p /app/project_path all
environment:
- PROJECT_PATH
- DATABASE_URL
volumes:
- ${PROJECT_PATH}:/app/project_path
ports:
- 3001:3001
restart: always
26 changes: 25 additions & 1 deletion documentation/docs/pages/docs/introduction/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,31 @@ rindexerdown
rindexer uses docker to spin up postgres databases for you when it runs locally so its recommended to install [docker](https://www.docker.com/products/docker-desktop/)
if you don't have it installed already.

**If you are using csv you do not need to install docker, it is only recommended with postgres.**
There's a pre-built docker image which can be used to run `rindexer` inside your dockerized infra:

[`ghcr.io/joshstevens19/rindexer`](https://github.com/users/joshstevens19/packages/container/package/rindexer)

### Create new project
To create a new `no-code` project in your current directory, you can run the following:

`docker run -it -v $PWD:/app/project_path ghcr.io/joshstevens19/rindexer new -p /app/project_path no-code`

### Use with existing project
To use it with an existing project and a running postgres instance you can simply invoke:

```
export PROJECT_PATH=/path/to/your/project
export DATABASE_URL="postgresql://user:pass@postgres/db"
docker-compose up -d
```

This will start all local indexing and if you have enabled the graphql endpoint, it will become exposed under:

http://localhost:3001


**If you are using csv you do not need to install docker, it is only recommended with postgres or if you're deploying rindexer in cloud environments.**

## Rust - optional

Expand Down
3 changes: 2 additions & 1 deletion graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "pkg index.js --output ../core/resources/rindexer-graphql --targets node16-linux-x64,node16-macos-x64,node16-win-x64"
"build": "pkg index.js --output ../core/resources/rindexer-graphql --targets node16-linux-x64,node16-macos-x64,node16-win-x64",
"build-linux": "pkg --debug index.js --output ../core/resources/rindexer-graphql-linux --targets node18-linux-x64"
},
"dependencies": {
"@graphile-contrib/pg-simplify-inflector": "^6.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use rindexer_erc20_filter_gen::*;
pub mod rindexer_erc20_filter_gen {
const _: () = {
::core::include_bytes!(
"/Users/joshstevens/code/rindexer/rindexer_rust_playground/abis/erc20-abi.json",
"../../../../../abis/erc20-abi.json",
);
};
#[allow(deprecated)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use rindexer_rocket_pool_eth_gen::*;
pub mod rindexer_rocket_pool_eth_gen {
const _: () = {
::core::include_bytes!(
"/Users/joshstevens/code/rindexer/rindexer_rust_playground/abis/erc20-abi.json",
"../../../../../abis/erc20-abi.json",
);
};
#[allow(deprecated)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use rindexer_world_gen::*;
pub mod rindexer_world_gen {
const _: () = {
::core::include_bytes!(
"/Users/joshstevens/code/rindexer/rindexer_rust_playground/abis/world.abi.json",
"../../../../../abis/world.abi.json",
);
};
#[allow(deprecated)]
Expand Down

0 comments on commit 4c4089a

Please sign in to comment.