/http-return-everything

A REST API server which returns container's environment.

Primary LanguageGo

Retrieving server context - A REST API server

GitHub Actions

gcr.io/pottava/re

Supported tags and respective Dockerfile links:
・v2.0 (prod/2.0/Dockerfile)
・v1.3 (prod/1.3/Dockerfile)

Usage

1. Set environment variables

Environment Variables Description
PORT Listening port. (default: 8080)
ENABLE_AWS Enable the AWS metadata endpoint. (default: true)
ENABLE_GCP Enable the Google Cloud metadata endpoint. (default: true)
ACCESS_LOG Send access logs to /dev/stdout. (default: true)
ACCESS_DETAIL_LOG Save HTTP request details (default: false)
CONTENT_ENCODING Compress response data if the request allows. (default: true)
CORS_ORIGIN Allowed CORS origin (default: *)

2. Run the application

$ docker run -d --rm -p 80:8080 gcr.io/pottava/re:v2.0

$ gcloud run deploy re --allow-unauthenticated \
    --image gcr.io/pottava/re:v2.0 \
    --set-env-vars ENABLE_GCP=1,ENABLE_AWS=0
  • with docker-compose.yml:
check:
  image: gcr.io/pottava/re:v2.0
  ports:
    - 80:8080
  environment:
    - ENABLE_AWS=false
    - ENABLE_GCP=false
    - ACCESS_LOG=false
    - CONTENT_ENCODING=false
  container_name: check
  • with Kubernetes deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: api
        image: gcr.io/pottava/re:v2.0
        imagePullPolicy: Always
        ports:
        - protocol: TCP
          containerPort: 8080
        env:
        - name: APP_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: APP_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: APP_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: APP_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: APP_POD_SERVICE_ACCOUNT
          valueFrom:
            fieldRef:
              fieldPath: spec.serviceAccountName
        readinessProbe:
          httpGet:
            path: /health
            port: 8080

3. Make HTTP GET requests

API spec

  • GET /

  • GET /app/envs/

  • GET /app/envs/{env}

  • GET /req/

  • GET /req/headers/

  • GET /req/headers/{header}