Skip to content

Commit ff0c984

Browse files
committed
first commit
0 parents  commit ff0c984

3,286 files changed

Lines changed: 389134 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Ignore files not needed for docker to build microservice image
2+
node_modules/*
3+
postgres/*
4+
typings/*
5+
*/.git*
6+
*.git*
7+
*.git
8+
*.md
9+
!gulpfile.js
10+
ci/
11+
.circleci/
12+
Vagrantfile
13+
concourse/
14+
infra/*
15+
vagrant/*
16+
docker/*
17+
deploy/*
18+
media/*
19+
data/*
20+
appspec.yml
21+
compose.yml
22+
docker-compose-prod.yml
23+
docker-compose.yml
24+
$virtualenv.tar.gz
25+
$node_modules.tar.gz

.gitlab-ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
image: docker:stable-git
2+
variables:
3+
PROJECT: "flb-socket"
4+
AWS_REGION: "ap-southeast-1"
5+
DOCKER_BUILDKIT: 1 # for faster docker builds
6+
7+
build_image:
8+
stage: build
9+
tags:
10+
- docker
11+
script:
12+
- 'export VERSION="$(git describe --always --tags)" ENVIRONMENT="$(basename $CI_COMMIT_REF_NAME)"'
13+
- 'docker build --build-arg ENVIRONMENT="${ENVIRONMENT}" -t ${PROJECT}-app:${VERSION} --target app .'
14+
15+
deploy:
16+
stage: deploy
17+
only:
18+
- /^deploy\/common$/
19+
tags:
20+
- docker
21+
script:
22+
- 'export VERSION="$(git describe --always --tags)" ENVIRONMENT="$(basename $CI_COMMIT_REF_NAME)"'
23+
- |-
24+
set -eu
25+
26+
wget https://github.com/springload/ecs-tool/releases/download/1.0.1/ecs-tool_1.0.1_linux_amd64.tar.gz -O /tmp/ecs-tool.tar.gz && tar -C /usr/bin -xvf /tmp/ecs-tool.tar.gz ecs-tool
27+
REPOSITORY=$(ecs-tool ecr-endpoint)
28+
eval $(ecs-tool ecr-login)
29+
30+
pids=""
31+
for image in "${PROJECT}-app"; do
32+
for tag in ${ENVIRONMENT}-${VERSION} ${ENVIRONMENT}-latest; do
33+
docker tag ${image}:${VERSION} ${REPOSITORY}/${image}:${tag}
34+
docker push ${REPOSITORY}/${image}:${tag} &
35+
pids="${pids} $!"
36+
done
37+
done
38+
39+
for p in $pids; do
40+
wait $p
41+
done
42+
43+
ecs-tool -e "${ENVIRONMENT}" deploy --image_tag "${ENVIRONMENT}-${VERSION}"

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM node:16-slim
2+
3+
RUN apt-get update -y --fix-missing \
4+
&& apt-get upgrade -y \
5+
&& apt-get install -y git
6+
7+
WORKDIR /app
8+
RUN adduser --system www && chown -R www /app
9+
USER www
10+
11+
# copy this first to not reinstall everything on a random file change
12+
COPY socket/package.json ./
13+
RUN npm install
14+
15+
# put the installed bin into PATH
16+
RUN echo 'export PATH=$PATH:$(npm bin)' >> ~/.profile
17+
SHELL ["/bin/sh", "-cl"]
18+
COPY ./socket ./
19+
20+
# here we can pass args during build stage
21+
ARG ENVIRONMENT=production
22+
# and use the ARG as an env var
23+
ENV ENV=$ENVIRONMENT
24+
25+
CMD npm run start
26+
27+
USER root
28+
ENV SOCKETCLUSTER_PORT=8000
29+
ENV SOCKETCLUSTER_WORKERS=5
30+
ENV SOCKETCLUSTER_BROKERS=5

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SocketCluster Sample App
2+
======
3+
4+
This is a sample SocketCluster app.
5+

broker.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var SCBroker = require('socketcluster/scbroker');
2+
var scClusterBrokerClient = require('scc-broker-client');
3+
4+
class Broker extends SCBroker {
5+
run() {
6+
console.log(' >> Broker PID:', process.pid);
7+
8+
// This is defined in server.js (taken from environment variable SC_CLUSTER_STATE_SERVER_HOST).
9+
// If this property is defined, the broker will try to attach itself to the SC cluster for
10+
// automatic horizontal scalability.
11+
// This is mostly intended for the Kubernetes deployment of SocketCluster - In this case,
12+
// The clustering/sharding all happens automatically.
13+
14+
if (this.options.clusterStateServerHost) {
15+
scClusterBrokerClient.attach(this, {
16+
stateServerHost: this.options.clusterStateServerHost,
17+
stateServerPort: this.options.clusterStateServerPort,
18+
mappingEngine: this.options.clusterMappingEngine,
19+
clientPoolSize: this.options.clusterClientPoolSize,
20+
authKey: this.options.clusterAuthKey,
21+
stateServerConnectTimeout: this.options.clusterStateServerConnectTimeout,
22+
stateServerAckTimeout: this.options.clusterStateServerAckTimeout,
23+
stateServerReconnectRandomness: this.options.clusterStateServerReconnectRandomness
24+
});
25+
}
26+
}
27+
}
28+
29+
new Broker();

docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3.4"
2+
3+
services:
4+
application:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
args:
9+
ENVIRONMENT: dev
10+
ports:
11+
- "38000:8000"
12+
environment:
13+
SOCKETCLUSTER_WORKERS: 10
14+
SOCKETCLUSTER_BROKERS: 10

dockerwait.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
This script waits for the master controller script to become available.
3+
With orchestrators like Kubernetes, the master controller file may be fed in through
4+
a volume container at runtime and so it is necessary to wait for it before launch.
5+
*/
6+
7+
var fsUtil = require('socketcluster/fsutil');
8+
var waitForFile = fsUtil.waitForFile;
9+
10+
var SOCKETCLUSTER_MASTER_DEFAULT_CONTROLLER = './server.js';
11+
var masterControllerPath = process.env.SOCKETCLUSTER_MASTER_CONTROLLER || SOCKETCLUSTER_MASTER_DEFAULT_CONTROLLER;
12+
var bootCheckInterval = Number(process.env.SOCKETCLUSTER_BOOT_CHECK_INTERVAL) || 200;
13+
var bootTimeout = Number(process.env.SOCKETCLUSTER_CONTROLLER_BOOT_TIMEOUT) || 10000;
14+
var bootStartTime = Date.now();
15+
16+
var errorMessage = `Failed to locate the master controller file at path ${masterControllerPath} ` +
17+
`before SOCKETCLUSTER_CONTROLLER_BOOT_TIMEOUT`;
18+
19+
waitForFile(masterControllerPath, bootCheckInterval, bootStartTime, bootTimeout, errorMessage)
20+
.catch((err) => {
21+
console.error('> Boot error: ' + err.message);
22+
process.exit(1);
23+
});

infra/common.tfvars

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project = "flb-socket"
2+
3+
aws_profile = "fleetbase"
4+
5+
ec2_key_name = "ecs"
6+
7+
kms = false
8+
9+
kms_common = false
10+
11+
services = ["app"]
12+
13+
environments = ["staging", "production", "qa", "dev"]
14+
15+
load_balancer_listener_port = 8000
16+
17+
deploy_user = "gitlab-flb-socket"
18+
19+
gitlab_project_id = 13
20+
21+
# we are reusing the load balancer from service
22+
23+
load_balancer_name = "flb-service"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terragrunt = {
2+
terraform {
3+
source = "git::ssh://git@gitlab.fleetbase.io/DevOps/infra.git//terraform//deploy-user?ref=v0.1-23-g7635de9"
4+
}
5+
6+
dependencies {}
7+
8+
include {
9+
path = "${find_in_parent_folders()}"
10+
}
11+
}

infra/common/ecr/terraform.tfvars

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terragrunt = {
2+
terraform {
3+
source = "git::ssh://git@gitlab.fleetbase.io/DevOps/infra.git//terraform//ecs/ecr?ref=v0.1-4-g498542d"
4+
}
5+
6+
dependencies {
7+
paths = ["../deploy-user"]
8+
}
9+
10+
include {
11+
path = "${find_in_parent_folders()}"
12+
}
13+
}

0 commit comments

Comments
 (0)