Fix workflow again. #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Indexer reusable build and run docker image for ECS service | ||
on: | ||
workflow_call: | ||
inputs: | ||
SERVICE: | ||
required: true | ||
type: string | ||
jobs: | ||
build-and-push-service: | ||
name: (${{ inputs.SERVICE }}) Check docker image build | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./indexer | ||
services: | ||
postgres: | ||
image: postgres:12-alpine | ||
env: | ||
POSTGRES_PASSWORD: dydxserver123 | ||
POSTGRES_USER: dydx_test | ||
ports: | ||
- 5432:5432 | ||
redis: | ||
image: redis:5.0.6-alpine | ||
ports: | ||
- 6379:6379 | ||
kafka: | ||
image: bitnami/kafka:3.4.0 | ||
env: | ||
KAFKA_CFG_ADVERTISED_HOST_NAME: localhost | ||
KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,EXTERNAL://localhost:9092 | ||
ports: | ||
- 9092:9092 | ||
init-kafka: | ||
image: bitnami/kafka:3.4.0 | ||
depends_on: | ||
- kafka | ||
entrypoint: [ '/bin/sh', '-c' ] | ||
command: | | ||
kafka-topics --bootstrap-server kafka:29092 --list | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-ender --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-vulcan --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-websockets-orderbooks --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-websockets-subaccounts --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-websockets-trades --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-websockets-markets --replication-factor 1 --partitions 1 | ||
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic to-websockets-candles --replication-factor 1 --partitions 1 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- name: Install pnpm | ||
run: | ||
npm install -g pnpm@6.34.0 | ||
- name: Build and install | ||
run: | | ||
pnpm install --loglevel warn --frozen-lockfile | ||
pnpm run build:prod:all | ||
- name: Build docker image | ||
id: build-image | ||
env: | ||
SERVICE: ${{ inputs.SERVICE }} | ||
run: | | ||
commit_hash=$(git rev-parse --short HEAD) | ||
DOCKER_BUILDKIT=1 docker build \ | ||
--platform amd64 \ | ||
-t service-base \ | ||
-f Dockerfile.service.remote \ | ||
--build-arg service=$SERVICE . | ||
- name: Setup database | ||
id: setup-database | ||
env: | ||
DB_PORT: 5432 | ||
NODE_ENV: test | ||
run: | | ||
cd packages/postgres && pnpm run migrate | ||
- name: Run docker image | ||
id: run-image | ||
env: | ||
SERVICE: ${{ inputs.SERVICE }} | ||
# `timeout` sends a `SIGTERM` to the process, resulting in the exit code 124, so we need to | ||
# ignore exit code 124. | ||
run: | | ||
timeout 30 docker run -e DB_PORT='5432' \ | ||
-e REDIS_URL='redis://localhost:6379' \ | ||
-e RATE_LIMIT_REDIS_URL='redis://localhost:6379' \ | ||
-e NODE_ENV='test' \ | ||
--network="host" \ | ||
service-base || ( [[ $? -eq 124 ]] && \ | ||
echo "Service container ran for 30 seconds with no errors" ) |