Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development to main #19

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/actions/build-and-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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 }}
3 changes: 3 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ inputs:
required: true
nomad-addr:
required: true
docker-tag:
required: true

runs:
using: "composite"
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ 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:
environment: dev
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 }}
17 changes: 6 additions & 11 deletions .github/workflows/live.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ 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:
environment: live
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 }}
7 changes: 4 additions & 3 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ 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:
environment: stage
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 }}
4 changes: 2 additions & 2 deletions operations/deploy-dev.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions operations/deploy-live.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions operations/deploy-stage.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading