Skip to content
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
2 changes: 1 addition & 1 deletion docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN wget -qO- "https://github.com/tx3-lang/trix/releases/download/${TRIX_VERSION
chmod +x /root/.tx3/default/bin/trix

ENV PREVIEW_API_URL=https://8000-skillful-employee-kb9ou6.us1.demeter.run
ENV MAINNET_API_URL=https://8000-ethereal-audience-bb83g6.us1.demeter.run
ENV MAINNET_API_URL=https://asteria.txpipe.io/api

ENV PREVIEW_TRP_URL=https://cardano-preview.trp-m1.demeter.run
ENV PREVIEW_TRP_API_KEY=trpjodqbmjblunzpbikpcrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ This transaction creates a `ShipState` UTxO locking min ada, a `ShipToken` (mint
#### You can query the next available ship and pilot token names using the following curl:

```
curl --location 'https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql' \
curl --location 'https://asteria.txpipe.io/api/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"query { nextShipTokenName(spacetimePolicyId: \"0291ae7aebaf064b785542093c2b13169effb34462301e68d4b44f43\", spacetimeAddress: \"addr1wypfrtn6awhsvjmc24pqj0ptzvtfalang33rq8ng6j6y7scnlkytx\") { shipName pilotName } }","variables":{}}'
```

#### You can query the tip of the chain using the following curl:

```
curl --location 'https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql' \
curl --location 'https://asteria.txpipe.io/api/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"query { lastSlot { slot } }","variables":{}}'
```
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/how-to-play/create-ship/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default function CreateShip(props: CreateShipProps) {
}

const handleFetchShipNumber = async () => {
const shipRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const shipRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { nextShipTokenName(spacetimePolicyId: \\\"0291ae7aebaf064b785542093c2b13169effb34462301e68d4b44f43\\\", spacetimeAddress: \\\"addr1wypfrtn6awhsvjmc24pqj0ptzvtfalang33rq8ng6j6y7scnlkytx\\\") { shipName pilotName } }\",\"variables\":{}}",
"method": "POST"
Expand All @@ -197,7 +197,7 @@ export default function CreateShip(props: CreateShipProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default function GatherFuel(props: GatherFuelProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function GatherToken(props: GatherTokenProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default function MineAsteria(props: MineAsteriaProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/how-to-play/move-ship/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default function MoveShip(props: MoveShipProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/how-to-play/quit-game/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function QuitGame(props: QuitGameProps) {
}

const handleFetchLastSlot = async () => {
const slotRes = await (await fetch("https://8000-ethereal-audience-bb83g6.us1.demeter.run/graphql", {
const slotRes = await (await fetch("https://asteria.txpipe.io/api/graphql", {
"headers": { "content-type": "application/json" },
"body": "{\"query\":\"query { lastSlot { slot } }\"}",
"method": "POST"
Expand Down
23 changes: 23 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Kubernetes

`chart/` deploys the Asteria challenge services from the images the workflows
publish to ghcr.io:

- **backend**: the GraphQL API (`backend/`, `ghcr.io/txpipe/asteria-backend`).
It reads chain state from a Blockfrost-compatible endpoint, set with
`backend.blockfrostBaseUrl`.
- **frontend**: the game site (`frontend/`, `ghcr.io/txpipe/asteria-frontend`),
disabled by default. Its backend URLs are inlined when the image is built, so
pointing it at another backend means building a new image.

The chart assumes no cluster, hostname, chain endpoint or image tag. Each
instance supplies them in its own values file, and the chart refuses to render
without them:

```sh
helm lint chart --values values.my-instance.yaml
helm template asteria chart --namespace asteria --values values.my-instance.yaml
```

Both images are built for `linux/amd64` only, so placement must land on x86
nodes. The backend runs as a non-root user on a read-only root filesystem.
11 changes: 11 additions & 0 deletions k8s/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: asteria
description: The Asteria challenge services, the GraphQL backend and the game frontend
type: application
# Chart version: this chart. appVersion: not tracked; each component's image
# is pinned in the instance values.
version: 0.1.0
home: https://github.com/txpipe/asteria
keywords:
- asteria
- cardano
20 changes: 20 additions & 0 deletions k8s/chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ .Chart.Name }} {{ .Chart.Version }}
{{ if .Values.backend.enabled }}
Backend ({{ .Values.backend.image.tag }}):
in-cluster: http://{{ include "asteria.componentName" (dict "root" . "component" "backend") }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.backend.service.port }}/graphql
{{- if .Values.backend.ingress.enabled }}
public: https://{{ .Values.backend.ingress.host }}{{ .Values.backend.ingress.path }}
{{- end }}
{{- end }}
{{ if .Values.frontend.enabled }}
Frontend ({{ .Values.frontend.image.tag }}):
in-cluster: http://{{ include "asteria.componentName" (dict "root" . "component" "frontend") }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.frontend.service.port }}/
{{- if .Values.frontend.ingress.enabled }}
public: https://{{ .Values.frontend.ingress.host }}{{ .Values.frontend.ingress.path }}
{{- end }}
{{- end }}

Smoke test:
kubectl -n {{ .Release.Namespace }} port-forward svc/{{ include "asteria.componentName" (dict "root" . "component" "backend") }} 18000:{{ .Values.backend.service.port }}
curl -s http://localhost:18000/graphql -H 'content-type: application/json' \
-d '{"query":"{ __typename }"}' # {"data":{"__typename":"QueryRoot"}}
61 changes: 61 additions & 0 deletions k8s/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- define "asteria.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "asteria.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "asteria.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/* Name of one component's objects: "<fullname>-<component>". */}}
{{- define "asteria.componentName" -}}
{{- printf "%s-%s" (include "asteria.fullname" .root) .component | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "asteria.selectorLabels" -}}
app.kubernetes.io/name: {{ include "asteria.name" .root }}
app.kubernetes.io/instance: {{ .root.Release.Name }}
app.kubernetes.io/component: {{ .component }}
{{- end -}}

{{- define "asteria.labels" -}}
helm.sh/chart: {{ include "asteria.chart" .root }}
{{ include "asteria.selectorLabels" . }}
app.kubernetes.io/version: {{ .values.image.tag | trunc 63 | quote }}
app.kubernetes.io/managed-by: {{ .root.Release.Service }}
{{- end -}}

{{- define "asteria.image" -}}
{{- $img := .values.image -}}
{{- $repository := required (printf "%s.image.repository is required" .component) $img.repository -}}
{{- $tag := required (printf "%s.image.tag is required" .component) $img.tag -}}
{{- if $img.digest -}}
{{- printf "%s:%s@%s" $repository $tag $img.digest -}}
{{- else -}}
{{- printf "%s:%s" $repository $tag -}}
{{- end -}}
{{- end -}}

{{/* A component's nodeSelector, falling back to the shared one. */}}
{{- define "asteria.placement" -}}
{{- with (default .root.Values.nodeSelector .values.nodeSelector) }}
nodeSelector:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with (default .root.Values.tolerations .values.tolerations) }}
tolerations:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}
120 changes: 120 additions & 0 deletions k8s/chart/templates/_workload.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{{/*
One component's Deployment, Service and optional Ingress. The caller passes
root (the chart context), component (its name), values (its values block),
env (the environment the component needs, which wins over values.env) and
probe (a probe handler).
*/}}
{{- define "asteria.workload" -}}
{{- $name := include "asteria.componentName" . -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $name }}
namespace: {{ .root.Release.Namespace }}
labels:
{{- include "asteria.labels" . | nindent 4 }}
spec:
replicas: {{ .values.replicaCount }}
selector:
matchLabels:
{{- include "asteria.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "asteria.selectorLabels" . | nindent 8 }}
spec:
{{- with include "asteria.placement" . | trim }}
{{- . | nindent 6 }}
{{- end }}
{{- with .values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .component }}
image: {{ include "asteria.image" . }}
imagePullPolicy: {{ .values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .values.port | int }}
env:
{{- range $key, $value := merge (dict) .env .values.env }}
- name: {{ $key }}
value: {{ $value | toString | quote }}
{{- end }}
{{- with .values.existingSecret }}
envFrom:
- secretRef:
name: {{ . }}
{{- end }}
readinessProbe:
{{- toYaml .probe | nindent 12 }}
periodSeconds: 10
livenessProbe:
{{- toYaml .probe | nindent 12 }}
periodSeconds: 20
failureThreshold: 3
{{- with .values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $name }}
namespace: {{ .root.Release.Namespace }}
labels:
{{- include "asteria.labels" . | nindent 4 }}
{{- with .values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .values.service.type }}
selector:
{{- include "asteria.selectorLabels" . | nindent 4 }}
ports:
- name: http
port: {{ .values.service.port }}
targetPort: http
{{- with .values.ingress }}
{{- if .enabled }}
{{- $host := required (printf "%s.ingress.host is required" $.component) .host }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $name }}
namespace: {{ $.root.Release.Namespace }}
labels:
{{- include "asteria.labels" $ | nindent 4 }}
annotations:
cert-manager.io/cluster-issuer: {{ required (printf "%s.ingress.clusterIssuer is required" $.component) .clusterIssuer }}
{{- with .annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ required (printf "%s.ingress.className is required" $.component) .className }}
rules:
- host: {{ $host }}
http:
paths:
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $name }}
port:
name: http
tls:
- hosts:
- {{ $host }}
secretName: {{ required (printf "%s.ingress.tlsSecretName is required" $.component) .tlsSecretName }}
{{- end }}
{{- end }}
{{- end -}}
11 changes: 11 additions & 0 deletions k8s/chart/templates/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.backend.enabled }}
{{- $values := .Values.backend }}
{{- $env := dict
"BLOCKFROST_BASE_URL" (required "backend.blockfrostBaseUrl is required" $values.blockfrostBaseUrl)
"ROCKET_ADDRESS" "0.0.0.0"
"ROCKET_PORT" $values.port
}}
{{- $probe := dict "httpGet" (dict "path" "/" "port" "http") }}
---
{{ include "asteria.workload" (dict "root" . "component" "backend" "values" $values "env" $env "probe" $probe) }}
{{- end }}
10 changes: 10 additions & 0 deletions k8s/chart/templates/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.frontend.enabled }}
{{- $values := .Values.frontend }}
{{- $env := dict
"HOSTNAME" "0.0.0.0"
"PORT" $values.port
}}
{{- $probe := dict "tcpSocket" (dict "port" "http") }}
---
{{ include "asteria.workload" (dict "root" . "component" "frontend" "values" $values "env" $env "probe" $probe) }}
{{- end }}
Loading
Loading