Skip to content

Commit

Permalink
Merge pull request #84 from okp4/build/docker-image
Browse files Browse the repository at this point in the history
🐳 Docker build & publish
  • Loading branch information
amimart authored Sep 7, 2023
2 parents 3a3c574 + a29f599 commit c429691
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*
!project.yaml
!src
!proto
!schema.graphql
!package.json
!yarn.lock
!tsconfig.json
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ jobs:
- name: Build project
run: |
yarn build
build-docker:
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Build docker image
run: |
docker build .
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ jobs:
dry: True
prettier_options: --check .
prettier_version: 3.0.2

lint-dockerfile:
runs-on: ubuntu-22.04
if: github.actor != 'dependabot[bot]'
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Lint dockerfile (hadolint)
uses: hadolint/[email protected]
49 changes: 49 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish

on:
push:
branches: [main]
tags: ["v*"]

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true

jobs:
publish-docker-images:
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Extract metadata (tags, labels) for Docker
id: docker_metadata
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }},value=nightly
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.vendor=OKP4
- name: Login to Docker registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_REGISTRY_ID }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

- name: Build and publish image(s)
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:18.16-alpine as build

WORKDIR /usr/src/app

COPY package.json .
COPY yarn.lock .

RUN yarn --frozen-lockfile

COPY . .

RUN yarn codegen && yarn build

FROM onfinality/subql-node-cosmos:v2.8.0

EXPOSE 3000

WORKDIR /srv/subql

RUN addgroup -S subql && adduser -S subql -G subql

USER subql

COPY --from=build --chown=subql:subql /usr/src/app/dist /srv/subql/dist
COPY --from=build --chown=subql:subql /usr/src/app/proto /srv/subql/proto
COPY --from=build --chown=subql:subql /usr/src/app/schema.graphql /srv/subql/schema.graphql
COPY --from=build --chown=subql:subql /usr/src/app/project.yaml /srv/subql/project.yaml

CMD ["-f", "/srv/subql"]
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ Generate the types:
yarn prepack
```

### Build Docker

🐳 Build the docker image:

```sh
docker build -t subql-okp4 .
```

Run it:

```sh
docker run -ti --rm --name my-indexer \
-e DB_HOST=postgres \
-e DB_PORT=5432 \
-e DB_DATABASE=subql \
-e DB_USER=subql \
-e DB_PASS=secret \
subql-okp4
```

Provide an alternate configuration:

```sh
docker run -ti --rm --name my-indexer \
-e DB_HOST=postgres \
-e DB_PORT=5432 \
-e DB_DATABASE=subql \
-e DB_USER=subql \
-e DB_PASS=secret \
-v /path/to/new-conf.yaml:/srv/subql/project.yaml \
subql-okp4
```

Give additional arguments to the subql node:

```sh
docker run -ti --rm --name my-indexer \
-e DB_HOST=postgres \
-e DB_PORT=5432 \
-e DB_DATABASE=subql \
-e DB_USER=subql \
-e DB_PASS=secret \
subql-okp4 --batch-size=32 --log-level=debug
```

> **_NOTE:_** To run the container in detached mode replace `-it --rm` by `-d` in the above commands.
## Usage

### Run
Expand Down

0 comments on commit c429691

Please sign in to comment.