diff --git a/.github/actions/build-and-push/action.yml b/.github/actions/build-and-push/action.yml index f7d450e..334835e 100755 --- a/.github/actions/build-and-push/action.yml +++ b/.github/actions/build-and-push/action.yml @@ -14,6 +14,7 @@ runs: - name: Log in to Docker Hub uses: docker/login-action@v1 with: + registry: ghcr.io username: ${{ inputs.docker-username }} password: ${{ inputs.docker-password }} @@ -23,4 +24,4 @@ runs: context: . file: ./Dockerfile push: true - tags: ${{ inputs.docker-username }}/api-service:${{ github.sha }},${{ inputs.docker-username }}/api-service:${{ inputs.docker-tag }} + tags: ghcr.io/ator-development/api-service:${{ inputs.docker-tag }} \ No newline at end of file diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml index 5f3f7f6..ab00340 100755 --- a/.github/actions/deploy/action.yml +++ b/.github/actions/deploy/action.yml @@ -8,6 +8,8 @@ inputs: required: true nomad-addr: required: true + docker-tag: + required: true runs: using: "composite" @@ -19,6 +21,7 @@ runs: NOMAD_TOKEN: ${{ inputs.nomad-token }} NOMAD_ADDR: ${{ inputs.nomad-addr }} run: | + sed -i 's/DEPLOY_TAG/${{ inputs.docker-tag }}/g' operations/deploy-${{ inputs.environment }}.hcl curl -L https://releases.hashicorp.com/nomad/1.6.3/nomad_1.6.3_linux_amd64.zip -o nomad.zip unzip nomad.zip ./nomad job run operations/deploy-${{ inputs.environment }}.hcl diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index bb27a72..971590e 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -16,9 +16,9 @@ jobs: - name: Build and push uses: ./.github/actions/build-and-push with: - docker-username: ${{ secrets.DOCKER_HUB_USERNAME }} - docker-password: ${{ secrets.DOCKER_HUB_PASSWORD }} - docker-tag: latest-dev + docker-username: ${{ github.actor }} + docker-password: ${{ secrets.GITHUB_TOKEN }} + docker-tag: ${{ github.sha }} - name: Deploy uses: ./.github/actions/deploy with: @@ -26,3 +26,4 @@ jobs: nomad-cacert: operations/admin-ui-ca.crt nomad-token: ${{ secrets.NOMAD_TOKEN_API_SERVICE_DEPLOY }} nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }} + docker-tag: ${{ github.sha }} diff --git a/.github/workflows/live.yml b/.github/workflows/live.yml index d18cd53..7c299aa 100644 --- a/.github/workflows/live.yml +++ b/.github/workflows/live.yml @@ -10,18 +10,12 @@ jobs: steps: - name: Check out the repo uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Log in to Github Container Registry - uses: docker/login-action@v3 + - name: Build and push + uses: ./.github/actions/build-and-push with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Tag latest - run: | - docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/api-service:latest-stage - docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/api-service:latest-stage ${{ secrets.DOCKER_HUB_USERNAME }}/api-service:latest - docker push ${{ secrets.DOCKER_HUB_USERNAME }}/api-service:latest + docker-username: ${{ github.actor }} + docker-password: ${{ secrets.GITHUB_TOKEN }} + docker-tag: ${{ github.sha }} - name: Deploy uses: ./.github/actions/deploy with: @@ -29,3 +23,4 @@ jobs: nomad-cacert: operations/admin-ui-ca.crt nomad-token: ${{ secrets.NOMAD_TOKEN_API_SERVICE_DEPLOY }} nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }} + docker-tag: ${{ github.sha }} diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index 32e3f61..b73e1af 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -16,9 +16,9 @@ jobs: - name: Build and push uses: ./.github/actions/build-and-push with: - docker-username: ${{ secrets.DOCKER_HUB_USERNAME }} - docker-password: ${{ secrets.DOCKER_HUB_PASSWORD }} - docker-tag: latest-stage + docker-username: ${{ github.actor }} + docker-password: ${{ secrets.GITHUB_TOKEN }} + docker-tag: ${{ github.sha }} - name: Deploy uses: ./.github/actions/deploy with: @@ -26,3 +26,4 @@ jobs: nomad-cacert: operations/admin-ui-ca.crt nomad-token: ${{ secrets.NOMAD_TOKEN_API_SERVICE_DEPLOY }} nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }} + docker-tag: ${{ github.sha }} diff --git a/operations/deploy-dev.hcl b/operations/deploy-dev.hcl index 1d95405..31bd80a 100755 --- a/operations/deploy-dev.hcl +++ b/operations/deploy-dev.hcl @@ -54,7 +54,7 @@ job "api-service-dev" { } config { - image = "svforte/api-service:latest-dev" + image = "ghcr.io/ator-development/api-service:DEPLOY_TAG" force_pull = true } @@ -97,7 +97,7 @@ job "api-service-dev" { "traefik.http.routers.api-dev.tls=true", "traefik.http.routers.api-dev.tls.certresolver=atorresolver", "traefik.http.routers.api-dev.middlewares=api-dev-ratelimit", - "traefik.http.middlewares.api-dev-ratelimit.ratelimit.average=30", + "traefik.http.middlewares.api-dev-ratelimit.ratelimit.average=300", "traefik.http.middlewares.api-dev-ratelimit.ratelimit.period=1m", "traefik-ec.enable=true", diff --git a/operations/deploy-live.hcl b/operations/deploy-live.hcl index 28fccb4..6c6a927 100755 --- a/operations/deploy-live.hcl +++ b/operations/deploy-live.hcl @@ -49,7 +49,7 @@ job "api-service-live" { } config { - image = "svforte/api-service:latest" + image = "ghcr.io/ator-development/api-service:DEPLOY_TAG" force_pull = true } @@ -97,9 +97,8 @@ job "api-service-live" { "traefik.http.routers.api-live.tls=true", "traefik.http.routers.api-live.tls.certresolver=atorresolver", "traefik.http.routers.api-live.middlewares=api-live-ratelimit", - "traefik.http.middlewares.api-live-ratelimit.ratelimit.average=300", - "traefik.http.middlewares.api-live-ratelimit.ratelimit.period=1m", - + "traefik.http.middlewares.api-live-ratelimit.ratelimit.average=1000" + "traefik-ec.enable=true", "traefik-ec.http.routers.api-live.rule=Host(`api.ec.anyone.tech`)", "traefik-ec.http.routers.api-live.entrypoints=https", diff --git a/operations/deploy-stage.hcl b/operations/deploy-stage.hcl index 03c69e4..50ed265 100755 --- a/operations/deploy-stage.hcl +++ b/operations/deploy-stage.hcl @@ -49,7 +49,7 @@ job "api-service-stage" { } config { - image = "svforte/api-service:latest-stage" + image = "ghcr.io/ator-development/api-service:DEPLOY_TAG" force_pull = true } @@ -97,7 +97,7 @@ job "api-service-stage" { "traefik.http.routers.api-stage.tls=true", "traefik.http.routers.api-stage.tls.certresolver=atorresolver", "traefik.http.routers.api-stage.middlewares=api-stage-ratelimit", - "traefik.http.middlewares.api-stage-ratelimit.ratelimit.average=300", + "traefik.http.middlewares.api-stage-ratelimit.ratelimit.average=3000", "traefik.http.middlewares.api-stage-ratelimit.ratelimit.period=1m", "traefik-ec.enable=true", diff --git a/src/app.ts b/src/app.ts index 36db176..46c063a 100755 --- a/src/app.ts +++ b/src/app.ts @@ -90,6 +90,47 @@ app.get('/relays/:fingerprint', async (req, res) => { } }); +app.get('/relays', async (req, res) => { + try { + const fingerprintsQuery = req.query.fingerprints as string | undefined; + + if (!fingerprintsQuery) { + return res.status(400).send('Fingerprints are required'); + } + + const fingerprints = fingerprintsQuery.split(','); + + if (fingerprints.length === 0) { + return res.status(400).send('Fingerprints are required'); + } + + const details = await onionooService.details(); + + const foundRelays = details.relays.filter((relay: { fingerprint: string; }) => + fingerprints.includes(relay.fingerprint) + ); + console.log('Found relays:', foundRelays); + + if (foundRelays.length > 0) { + const relays = foundRelays.map((foundRelay : any) => ({ + fingerprint: foundRelay.fingerprint, + running: foundRelay.running, + consensus_weight: foundRelay.consensus_weight, + observed_bandwidth: foundRelay.observed_bandwidth, + measured: foundRelay.measured + })); + console.log('Result relays:', relays); + return res.json(relays); + } else { + console.log("No relays found"); + return res.status(404).send('No relays found'); + } + } catch (error) { + console.error(error); + res.status(500).send('Error querying Onionoo'); + } +}); + app.get('/relay-map/', async (req, res) => { try { const details = await onionooService.details();