Skip to content

Commit b0a997f

Browse files
committed
First commit
1 parent 799b9e0 commit b0a997f

9 files changed

Lines changed: 1566 additions & 37 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Makefile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
GITHUB_ORG := $(shell echo ${REPOSITORY} | cut -d "/" -f 2)
77
GITHUB_REPO := $(shell echo ${REPOSITORY} | cut -d "/" -f 3)
88

9-
run: create-db-user
9+
run:
1010
@echo "Set CIRCLECI environment variables\n"
1111
export AWS_ACCESS_KEY_ID=$(shell aws secretsmanager get-secret-value --region ${region} --secret-id=ci-user-aws-keys${randomSeed} | jq -r '.SecretString'| jq -r .access_key_id)
1212
export AWS_SECRET_ACCESS_KEY=$(shell aws secretsmanager get-secret-value --region ${region} --secret-id=ci-user-aws-keys${randomSeed} | jq -r '.SecretString'| jq -r .secret_key)
@@ -17,16 +17,8 @@ run: create-db-user
1717
curl -X POST https://circleci.com/api/v1.1/project/github/${GITHUB_ORG}/${GITHUB_REPO}/follow?circle-token=${CIRCLECI_API_KEY}
1818
@echo "\nDone"
1919

20-
create-db-user:
21-
export REGION=${region}; \
22-
export SEED=${randomSeed}; \
23-
export PROJECT_NAME=${PROJECT_NAME}; \
24-
export ENVIRONMENT=${ENVIRONMENT}; \
25-
export DATABASE=${database}; \
26-
sh ./db-ops/create-db-user.sh
27-
2820
summary:
29-
@echo "zero-deployable-backend:"
21+
@echo "zero-deployable-node-backend:"
3022
@echo "- Repository URL: ${REPOSITORY}"
3123
@echo "- Deployment Pipeline URL: https://app.circleci.com/pipelines/github/${GITHUB_ORG}/${GITHUB_REPO}"
3224
@echo $(shell echo ${ENVIRONMENT} | grep prod > /dev/null && echo "- Production API: ${productionBackendSubdomain}${productionHostRoot}")

templates/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

templates/Dockerfile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
FROM golang:1.13.7-alpine3.11 as builder
1+
FROM node:14.9-alpine
22
WORKDIR /app
33
COPY . .
4-
RUN go build -o <% .Name %> main.go
4+
RUN npm i
55

6-
FROM alpine:3.11
7-
RUN apk add --update bash ca-certificates
8-
WORKDIR /app
9-
COPY --from=builder /app/<% .Name %> .
10-
11-
ENTRYPOINT ["/app/<% .Name %>"]
6+
ENTRYPOINT ["/app/<% .Name %>"]

templates/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
build:
2-
go build -o <% .Name %> main.go
1+
install:
2+
npm i
33

44
run:
5-
SERVER_PORT=80 go run main.go
5+
PORT=80 node app.js

templates/app.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const PORT = 3000;
1+
var aws = require('aws-sdk');
2+
var cfsign = require('aws-cloudfront-sign');
3+
var express = require('express');
24

3-
const express = require('express');
4-
const app = express();
5-
6-
const aws = require('aws-sdk');
7-
aws.config.update({ accessKeyId: process.env.ACCESS_KEY_ID, secretAccessKey: process.env.SECRET_ACCESS_KEY });
8-
const s3 = new aws.S3();
5+
var app = express();
6+
var s3 = new aws.S3();
97

108
app.get('/presigned/:key', (req, res) => {
119
var params = {
@@ -28,15 +26,39 @@ app.get('/presigned/:key', (req, res) => {
2826

2927
app.get('/:key', (req, res) => {
3028
var params = {
31-
Bucket: process.env.S3_BUCKET,
32-
Key: req.params.key
29+
keypairId: process.env.CF_KEYPAIR_ID,
30+
privateKeyString: process.env.CF_KEYPAIR_SECRET_KEY,
31+
expireTime: new Date().getTime() + 30000 // defaults to 30s
3332
};
3433

35-
var url = s3.getSignedUrl('getObject', params);
34+
var url = cfsign.getSignedUrl(
35+
`https://files.commit.dev/${req.params.key}`,
36+
params
37+
);
38+
3639
console.log(url);
3740
res.redirect(url);
3841
});
3942

40-
app.listen(PORT, () => {
41-
console.log(`Example app listening at http://localhost:${PORT}`);
43+
app.get('/status/ready', (req, res) => {
44+
res.send("OK");
45+
});
46+
47+
app.get('/status/alive', (req, res) => {
48+
res.send("OK");
49+
});
50+
51+
app.get('/status/about', (req, res) => {
52+
res.send({
53+
podName: process.env.POD_NAME
54+
});
55+
});
56+
57+
var port = process.env.PORT;
58+
if (!port) {
59+
port = 3000;
60+
}
61+
62+
app.listen(port, () => {
63+
console.log(`Example app listening at http://localhost:${port}`);
4264
});

templates/kubernetes/base/deployment.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ spec:
2222
memory: 256Mi
2323
cpu: 0.5
2424
livenessProbe:
25-
exec:
26-
command:
27-
- rm
28-
- /tmp/service-alive
25+
httpGet:
26+
port: http
27+
path: /status/alive
2928
initialDelaySeconds: 5
3029
periodSeconds: 5
3130
readinessProbe:
@@ -58,6 +57,16 @@ spec:
5857
secretKeyRef:
5958
name: <% .Name %>
6059
key: DATABASE_PASSWORD
60+
- name: CF_KEYPAIR_ID
61+
valueFrom:
62+
secretKeyRef:
63+
name: cf_keypair
64+
key: keypair_id
65+
- name: CF_KEYPAIR_SECRET_KEY
66+
valueFrom:
67+
secretKeyRef:
68+
name: cf_keypair
69+
key: secret_key
6170
---
6271
apiVersion: autoscaling/v1
6372
kind: HorizontalPodAutoscaler

0 commit comments

Comments
 (0)