diff --git a/.build/docker/Dockerfile b/.build/docker/Dockerfile new file mode 100644 index 0000000..4097894 --- /dev/null +++ b/.build/docker/Dockerfile @@ -0,0 +1,16 @@ +FROM oven/bun:alpine + +WORKDIR /app + +COPY . . + +RUN bun install + +# Expose the port the app runs on +EXPOSE 5384 + +# Entry script to handle conditional startup +COPY .build/docker/docker-entrypoint.sh ./docker-entrypoint.sh +RUN chmod +x ./docker-entrypoint.sh + +ENTRYPOINT ["sh", "./docker-entrypoint.sh"] diff --git a/.build/docker/docker-compose.yml b/.build/docker/docker-compose.yml new file mode 100644 index 0000000..2689c1d --- /dev/null +++ b/.build/docker/docker-compose.yml @@ -0,0 +1,22 @@ +services: + seda-data-proxy: + build: + context: ../.. + dockerfile: .build/docker/Dockerfile + ports: + - "5384:5384" + # environment: + # # Provide the private key if available + # SEDA_DATA_PROXY_PRIVATE_KEY: ${SEDA_DATA_PROXY_PRIVATE_KEY} + # + # volumes: + # # Mount config.json if it exists in the host folder + # - ./config.json:/app/config.json:ro + # # Mount a data proxy private key file + # - ./data-proxy-private-key.json:/app/data-proxy-private-key.json:ro + networks: + - proxy-network + +networks: + proxy-network: + driver: bridge diff --git a/.build/docker/docker-entrypoint.sh b/.build/docker/docker-entrypoint.sh new file mode 100644 index 0000000..39d153a --- /dev/null +++ b/.build/docker/docker-entrypoint.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Initialize flags for config.json and private key +CONFIG_EXISTS=false +PK_EXISTS=false + +# Check if config.json exists +if [ -f /app/config.json ]; then + echo "config.json detected" + CONFIG_EXISTS=true +else + echo "config.json not found" +fi + +# Check if data-proxy-private-key.json exists +if [ -f /app/data-proxy-private-key.json ]; then + echo "data-proxy-private-key.json detected" + PK_EXISTS=true +elif [ -n "$SEDA_DATA_PROXY_PRIVATE_KEY" ]; then + # If private key file does not exist, check if the private key is provided via environment variable + echo "Private key provided via environment variable" + echo "$SEDA_DATA_PROXY_PRIVATE_KEY" >/app/data-proxy-private-key.json + PK_EXISTS=true +else + echo "No private key provided" +fi + +run_bun_command() { + if ! bun "$@"; then + echo "Failed to run: bun $*" + exit 1 + fi +} + +# Determine the command to run based on the presence of config.json and private key +if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then + # Both config.json and private key are provided + echo "Running with config and private key" + RUN_CMD="start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json" +elif [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = false ]; then + # Only config.json is provided + echo "Running with config only" + run_bun_command start init + RUN_CMD="start run --config /app/config.json" +else + # Neither config.json nor private key is provided + echo "Running with --disable-proof" + run_bun_command start init + RUN_CMD="start run --disable-proof" +fi + +# Execute the final command +run_bun_command $RUN_CMD diff --git a/.env.example b/.env.example index 361ee99..103078e 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -SEDA_DATA_PROXY_PRIVATE_KEY= \ No newline at end of file +SEDA_DATA_PROXY_PRIVATE_KEY= diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f965794 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,80 @@ +name: ๐Ÿš€ Release + +on: + push: + tags: ["*"] + +permissions: + contents: write + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: sedaprotocol/seda-data-proxy + +jobs: + build-and-push: + name: ๐Ÿณ Build and Push Docker Image + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 + + - name: ๐Ÿท๏ธ Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=edge,branch=main + + - name: ๐Ÿ› ๏ธ Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: ๐Ÿ” Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: ๐Ÿ—๏ธ Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: .build/docker/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + create-release: + name: ๐Ÿ“ฆ Create GitHub Release + needs: build-and-push + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 + + - name: ๐Ÿ“ Generate Changelog + id: changelog + uses: TriPSs/conventional-changelog-action@v5.3.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + output-file: false + skip-commit: true + skip-tag: true + skip-git-pull: true + git-push: false + + - name: ๐ŸŽ‰ Create GitHub Release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + generateReleaseNotes: true + body: ${{ steps.changelog.outputs.changelog }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73e8e6c..4467016 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: 'Test' +name: ๐Ÿงช Test on: [pull_request, push] jobs: diff --git a/.gitignore b/.gitignore index 5f17fc5..0634828 100644 --- a/.gitignore +++ b/.gitignore @@ -174,4 +174,4 @@ dist # Finder (MacOS) folder config .DS_Store config.json -data-proxy-private-key.json \ No newline at end of file +data-proxy-private-key.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..05cf33b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9eac709 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +.PHONY: build run stop up clean logs ssh + +# Define the docker-compose file location +DOCKER_COMPOSE_FILE := .build/docker/docker-compose.yml + +# Build the Docker image +build: + docker compose -f $(DOCKER_COMPOSE_FILE) build + +# Run the Docker container +run: + docker compose -f $(DOCKER_COMPOSE_FILE) up + +# Stop the Docker container +stop: + docker compose -f $(DOCKER_COMPOSE_FILE) down + +# Build and run the Docker container +up: build run + +# Clean up Docker resources +clean: + docker compose -f $(DOCKER_COMPOSE_FILE) down --rmi all --volumes --remove-orphans + +# Show logs +logs: + docker compose -f $(DOCKER_COMPOSE_FILE) logs -f + +# SSH into the running container +ssh: + docker compose -f $(DOCKER_COMPOSE_FILE) exec seda-data-proxy sh diff --git a/bunfig.toml b/bunfig.toml index a1f7644..9e75dd2 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,2 +1,2 @@ [test] -preload = ["./test-setup.ts"] \ No newline at end of file +preload = ["./test-setup.ts"]