Skip to content

Commit

Permalink
Add docker container (#22)
Browse files Browse the repository at this point in the history
* Add docker container

* Add docker run script

* Fix readme

* Update README.md

Co-authored-by: Aaron Scheiner <[email protected]>

---------

Co-authored-by: Aaron Scheiner <[email protected]>
  • Loading branch information
vponline and aquarat authored Oct 9, 2023
1 parent c356371 commit cba8599
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 12 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,21 @@ The global coefficient applied to all deviation checks. Used to differentiate al
```jsonc
"deviationThresholdCoefficient": 1,
```

## Docker

### Build

The docker image can be built by running the following command from the root directory:

```sh
yarn docker:build
```

### Run

The docker image can be run locally with:

```sh
yarn docker:run
```
66 changes: 66 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ARG build=local

FROM node:18.14.0-alpine3.17 AS environment

ENV name="airseekerv2" \
appDir="/app" \
buildDir="/build"
ENV packageDir="${buildDir}/package"

# Build preparation
FROM environment AS preparation

WORKDIR ${buildDir}

RUN apk add --update --no-cache git

# Install pnpm
RUN npm install -g pnpm

# Source preparation - local
FROM preparation as sourcelocal

COPY . ${buildDir}

# Source preparation - git
FROM preparation as sourcegit

ARG branch=main
ARG repository=https://github.com/api3dao/airseeker-v2.git

RUN git clone --single-branch --branch ${branch} ${repository} ${buildDir}

# Production dependencies
FROM source${build} AS deps

RUN pnpm install --prod --no-optional --ignore-scripts

# Production source code
FROM source${build} AS build

RUN pnpm install && \
pnpm build && \
pnpm pack && \
mkdir -p ${packageDir} && \
tar -xf *.tgz -C ${packageDir} --strip-components 1

# Result image
FROM environment

WORKDIR ${appDir}

LABEL application=${name} \
description="AirseekerV2 container"


COPY --from=deps ${buildDir}/node_modules ./node_modules
COPY --from=build ${packageDir} .

# Create Airseeker user
RUN addgroup -S ${name} && \
adduser -h ${appDir} -s /bin/false -S -D -H -G ${name} ${name} && \
chown -R ${name} ${appDir}

USER ${name}

CMD ["node", "dist/index.js"]
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
"node": "^18.14.0",
"pnpm": "^8.8.0"
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf coverage dist",
"dev": "nodemon --ext ts,js,json,env --exec \"pnpm ts-node src/index.ts\"",
"eslint:check": "eslint . --ext .js,.ts --max-warnings 0",
"eslint:fix": "eslint . --ext .js,.ts --fix",
"prepare": "husky install",
"prettier:check": "prettier --check \"./**/*.{js,ts,md,json}\"",
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,json}\"",
"test": "jest",
"tsc": "tsc --project ."
},
"files": [
"dist",
"*.js"
],
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/lodash": "^4.14.199",
Expand All @@ -44,5 +36,18 @@
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"zod": "^3.22.2"
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf coverage dist",
"dev": "nodemon --ext ts,js,json,env --exec \"pnpm ts-node src/index.ts\"",
"eslint:check": "eslint . --ext .js,.ts --max-warnings 0",
"eslint:fix": "eslint . --ext .js,.ts --fix",
"prettier:check": "prettier --check \"./**/*.{js,ts,md,json}\"",
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,json}\"",
"test": "jest",
"tsc": "tsc --project .",
"docker:build": "docker build -t api3/airseekerv2:latest -f docker/Dockerfile .",
"docker:run": "docker run -it --rm api3/airseekerv2:latest"
}
}

0 comments on commit cba8599

Please sign in to comment.