-
Notifications
You must be signed in to change notification settings - Fork 60.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36186 from github/repo-sync
Repo sync
- Loading branch information
Showing
11 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: webapp | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: webapp | ||
template: | ||
metadata: | ||
labels: | ||
app: webapp | ||
annotations: | ||
# Our internal logs aren't structured so we use logfmt_sloppy to just log stdout and error | ||
# See https://thehub.github.com/epd/engineering/dev-practicals/observability/logging/ for more details | ||
fluentbit.io/parser: logfmt_sloppy | ||
observability.github.com/splunk_index: docs-internal | ||
spec: | ||
dnsPolicy: Default | ||
containers: | ||
- name: webapp | ||
image: docs-internal | ||
resources: | ||
requests: | ||
cpu: 1000m | ||
memory: 4500Mi | ||
limits: | ||
cpu: 8000m | ||
memory: 16Gi | ||
ports: | ||
- name: http | ||
containerPort: 4000 | ||
protocol: TCP | ||
envFrom: | ||
- secretRef: | ||
name: vault-secrets | ||
- configMapRef: | ||
name: kube-cluster-metadata | ||
# application-config is created at deploy time from | ||
# configuration set in config/moda/configuration/*/env.yaml | ||
- configMapRef: | ||
name: application-config | ||
# Zero-downtime deploys | ||
# https://thehub.github.com/engineering/products-and-services/internal/moda/feature-documentation/pod-lifecycle/#required-prestop-hook | ||
# https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks | ||
lifecycle: | ||
preStop: | ||
exec: | ||
command: ['sleep', '5'] | ||
readinessProbe: | ||
initialDelaySeconds: 5 | ||
httpGet: | ||
# WARNING: This should be updated to a meaningful endpoint for your application which will return a 200 once the app is fully started. | ||
# See: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes | ||
path: /healthcheck | ||
port: http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: webapp | ||
labels: | ||
service: webapp | ||
annotations: | ||
moda.github.net/domain-name: 'docs-internal-%environment%.service.%region%.github.net' | ||
# HTTP app reachable inside GitHub's network (employee website) | ||
moda.github.net/load-balancer-type: internal-http | ||
spec: | ||
ports: | ||
- name: http | ||
port: 4000 | ||
protocol: TCP | ||
targetPort: http | ||
selector: | ||
app: webapp | ||
type: LoadBalancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
data: | ||
MODA_APP_NAME: docs-internal | ||
NODE_ENV: production | ||
NODE_OPTIONS: '--max-old-space-size=4096' | ||
PORT: '4000' | ||
ENABLED_LANGUAGES: 'en,zh,es,pt,ru,ja,fr,de,ko' | ||
RATE_LIMIT_MAX: '21' | ||
# Moda uses a non-default port for sending datadog metrics | ||
DD_DOGSTATSD_PORT: '28125' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
data: | ||
MODA_APP_NAME: docs-internal | ||
# Identifies the service deployment environment as production | ||
# Equivalent to HEAVEN_DEPLOYED_ENV === 'production' | ||
MODA_PROD_SERVICE_ENV: 'true' | ||
NODE_ENV: production | ||
NODE_OPTIONS: '--max-old-space-size=4096' | ||
PORT: '4000' | ||
ENABLED_LANGUAGES: 'en,zh,es,pt,ru,ja,fr,de,ko' | ||
RATE_LIMIT_MAX: '21' | ||
# Moda uses a non-default port for sending datadog metrics | ||
DD_DOGSTATSD_PORT: '28125' | ||
# Identifies the service deployment environment as production | ||
# Equivalent to HEAVEN_DEPLOYED_ENV === 'production' | ||
MODA_PROD_SERVICE_ENV: 'true' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// We cannot use Cookies.get() on the frontend for httpOnly cookies | ||
// so we need to make a request to the server to get the cookies | ||
|
||
type DotcomCookies = { | ||
dotcomUsername?: string | ||
isStaff?: boolean | ||
} | ||
|
||
let cachedCookies: DotcomCookies | null = null | ||
let inFlightPromise: Promise<DotcomCookies> | null = null | ||
let tries = 0 | ||
|
||
const GET_COOKIES_ENDPOINT = '/api/cookies' | ||
const MAX_TRIES = 3 | ||
|
||
// Fetches httpOnly cookies from the server and cache the result | ||
// We use an in-flight promise to avoid duplicate requests | ||
async function fetchCookies(): Promise<DotcomCookies> { | ||
if (cachedCookies) { | ||
return cachedCookies | ||
} | ||
|
||
// If request is already in progress, return the same promise | ||
if (inFlightPromise) { | ||
return inFlightPromise | ||
} | ||
|
||
if (tries > MAX_TRIES) { | ||
// In prod, fail without a serious error | ||
console.error('Failed to fetch cookies after 3 tries') | ||
// In dev, be loud about the issue | ||
if (process.env.NODE_ENV === 'development') { | ||
throw new Error('Failed to fetch cookies after 3 tries') | ||
} | ||
|
||
return Promise.resolve({}) | ||
} | ||
|
||
inFlightPromise = fetch(GET_COOKIES_ENDPOINT) | ||
.then((response) => { | ||
tries++ | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch cookies: ${response.statusText}`) | ||
} | ||
return response.json() as Promise<DotcomCookies> | ||
}) | ||
.then((data) => { | ||
cachedCookies = data | ||
return data | ||
}) | ||
.finally(() => { | ||
// Clear the in-flight promise regardless of success or failure | ||
// On success, subsequent calls will return the cached value | ||
// On failure, subsequent calls will retry the request up to MAX_TRIES times | ||
inFlightPromise = null | ||
}) | ||
|
||
return inFlightPromise | ||
} | ||
|
||
export async function getIsStaff(): Promise<boolean> { | ||
const cookies = await fetchCookies() | ||
return cookies.isStaff || false | ||
} | ||
|
||
export async function getDotcomUsername(): Promise<string> { | ||
const cookies = await fetchCookies() | ||
return cookies.dotcomUsername || '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters