Skip to content

Commit a7e6d4e

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 3db0ff1 + 1fcd665 commit a7e6d4e

File tree

13 files changed

+501
-41
lines changed

13 files changed

+501
-41
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM nginx:1.13
2+
3+
COPY deploy/default.conf /etc/nginx/conf.d
4+
5+
RUN mkdir /files
6+
COPY build/libs/sourcerer-app.jar /files/download
7+
COPY src/install/install /files/install

build.gradle

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ plugins {
1717
id 'de.fuerstenau.buildconfig' version '1.1.8'
1818
}
1919

20+
21+
2022
apply plugin: "idea"
2123
apply plugin: "java"
2224
apply plugin: "kotlin"
@@ -25,15 +27,33 @@ apply plugin: "com.google.protobuf"
2527
apply plugin: "org.junit.platform.gradle.plugin"
2628

2729
buildConfig {
30+
ext.environment = project.hasProperty('env') &&
31+
env == 'production' ? 'prod' : 'dev'
32+
2833
clsName = 'BuildConfig'
2934
packageName = 'app'
35+
36+
// API.
37+
def apiBasePath = 'https://staging.eng.sourcerer.io/api/commit'
38+
if (ext.environment == 'prod') {
39+
apiBasePath = 'https://sourcerer.io/api/commit'
40+
}
41+
apiBasePath = project.hasProperty('api') ? api : apiBasePath
42+
43+
buildConfigField 'String', 'API_BASE_PATH', apiBasePath
44+
45+
// Common.
46+
buildConfigField 'String', 'PROFILE_URL', 'https://sourcerer.io/'
47+
48+
// App version.
3049
buildConfigField 'int', 'VERSION_CODE', '1'
3150
buildConfigField 'String', 'VERSION', '0.0.1'
32-
buildConfigField 'String', 'PROFILE_URL', 'https://sourcerer.io/'
33-
buildConfigField 'String', 'API_BASE_URL', 'http://localhost:3181'
51+
52+
// Google Analytics.
3453
buildConfigField 'String', 'GA_BASE_PATH', 'http://www.google-analytics.com'
3554
buildConfigField 'String', 'GA_TRACKING_ID', 'UA-107129190-2'
3655
buildConfigField 'boolean', 'IS_GA_ENABLED', 'true'
56+
3757
buildConfig
3858
}
3959

@@ -98,4 +118,6 @@ jar {
98118
exclude "META-INF/*.DSA"
99119
exclude "META-INF/*.RSA"
100120
}
121+
122+
baseName 'sourcerer-app'
101123
}

deploy/GradleDockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM gradle:4.2.0
2+
3+
USER root
4+
WORKDIR /root/app

deploy/Jenkinsfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
podTemplate(label: 'build-pod-sourcerer-app',
2+
containers: [
3+
containerTemplate(name: 'jnlp', image: 'gcr.io/cloud-solutions-images/jenkins-k8s-slave', args: '${computer.jnlpmac} ${computer.name}'),
4+
containerTemplate(name: 'gradle', image: 'gcr.io/sourcerer-1377/gradle:4.2.0', ttyEnabled: true, command: 'tail -f /dev/null')
5+
],
6+
envVars: [
7+
envVar(key: 'CONTAINER_TAG', value: "${env.BRANCH_NAME}.${env.BUILD_NUMBER}")
8+
],
9+
volumes: [
10+
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
11+
hostPathVolume(hostPath: '/usr/bin/docker', mountPath: '/usr/bin/docker')
12+
]
13+
) {
14+
node('build-pod-sourcerer-app') {
15+
def namespace = 'staging'
16+
def benv = 'development'
17+
if (env.BRANCH_NAME == 'master') {
18+
benv = 'production'
19+
namespace = 'production'
20+
}
21+
22+
stage('checkout') {
23+
checkout scm
24+
}
25+
26+
stage('build jar and test') {
27+
container('gradle') {
28+
sh("ENV=${benv} ./do.sh build_jar_inside")
29+
}
30+
}
31+
32+
stage('build nginx') {
33+
container('gradle') {
34+
sh("./do.sh build_prod_inside")
35+
}
36+
}
37+
38+
stage('push') {
39+
sh("./do.sh push")
40+
}
41+
42+
stage('deploy') {
43+
println "Deploying to ${namespace} kubernetes namespace"
44+
sh("NAMESPACE=${namespace} ./do.sh deploy")
45+
}
46+
}
47+
}
48+

deploy/default.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
geo $dollar {
2+
default "$";
3+
}
4+
5+
server {
6+
listen 80 default_server;
7+
server_name _;
8+
9+
location /install {
10+
alias /files/install;
11+
12+
sub_filter "${dollar}SERVER_EXT" 'https://$host';
13+
sub_filter_types *;
14+
}
15+
16+
location / {
17+
root /files/;
18+
}
19+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
kind: Service
2+
metadata:
3+
name: sourcerer-app
4+
labels:
5+
app: sourcerer-app
6+
spec:
7+
type: ClusterIP
8+
ports:
9+
- port: 80
10+
targetPort: 80
11+
selector:
12+
app: sourcerer-app
13+
---
14+
apiVersion: apps/v1beta1
15+
kind: Deployment
16+
metadata:
17+
name: sourcerer-app
18+
spec:
19+
replicas: 2
20+
template:
21+
metadata:
22+
labels:
23+
app: sourcerer-app
24+
spec:
25+
containers:
26+
- name: sourcerer-app
27+
image: gcr.io/sourcerer-1377/sourcerer-app:CONTAINER_TAG
28+
imagePullPolicy: Always
29+
resources:
30+
requests:
31+
cpu: 100m
32+
memory: 100Mi

deploy/sourcerer-app-staging.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
kind: Service
2+
metadata:
3+
name: sourcerer-app
4+
labels:
5+
app: sourcerer-app
6+
spec:
7+
type: ClusterIP
8+
ports:
9+
- port: 80
10+
targetPort: 80
11+
selector:
12+
app: sourcerer-app
13+
---
14+
apiVersion: apps/v1beta1
15+
kind: Deployment
16+
metadata:
17+
name: sourcerer-app
18+
spec:
19+
replicas: 1
20+
template:
21+
metadata:
22+
labels:
23+
app: sourcerer-app
24+
spec:
25+
containers:
26+
- name: sourcerer-app
27+
image: gcr.io/sourcerer-1377/sourcerer-app:CONTAINER_TAG
28+
imagePullPolicy: Always
29+
resources:
30+
requests:
31+
cpu: 100m
32+
memory: 100Mi

do.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
#-------------------#
4+
#----- Helpers -----#
5+
#-------------------#
6+
7+
usage() {
8+
echo "$0 [COMMAND] [ARGUMENTS]"
9+
echo " Commands:"
10+
echo " - build_jar: build jar"
11+
echo " - build_prod_inside: build nginx container"
12+
echo " - run_jar: run jar"
13+
echo " - run_prod: start nginx container"
14+
}
15+
16+
fn_exists() {
17+
type $1 2>/dev/null | grep -q 'is a function'
18+
}
19+
20+
COMMAND=$1
21+
shift
22+
ARGUMENTS=${@}
23+
24+
TAG="${CONTAINER_TAG:-latest}"
25+
NAMESPACE="${NAMESPACE:-staging}"
26+
ENV="${ENV:-development}"
27+
VOLUME="${BUILD_VOLUME:-$PWD}"
28+
PROJECT=sourcerer-app
29+
PORT=3182
30+
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$TAG
31+
GRADLE_VERSION=4.2.0
32+
33+
#--------------------#
34+
#----- Commands -----#
35+
#--------------------#
36+
37+
# run only inside build container
38+
build_jar_inside() {
39+
gradle -Penv=$ENV build
40+
}
41+
42+
build_jar() {
43+
docker run -i -v $VOLUME:/home/gradle/app --workdir=/home/gradle/app -e ENV=$ENV \
44+
gradle:$GRADLE_VERSION \
45+
./do.sh build_jar_inside
46+
}
47+
48+
build_prod_inside() {
49+
docker build -t $REPO_NAME .
50+
}
51+
52+
deploy() {
53+
sed "s#CONTAINER_TAG#$TAG#" ./deploy/sourcerer-app-$NAMESPACE.yaml > /tmp/deploy.yaml
54+
kubectl --namespace=$NAMESPACE apply -f /tmp/deploy.yaml
55+
}
56+
57+
######################
58+
59+
run_jar() {
60+
docker run -i -v $VOLUME:/app --workdir=/app gradle:$GRADLE_VERSION \
61+
java -jar build/libs/app.jar
62+
}
63+
64+
run_prod() {
65+
docker run -i -p $PORT:80 $REPO_NAME
66+
}
67+
68+
push() {
69+
gcloud docker -- push $REPO_NAME
70+
}
71+
72+
#---------------------#
73+
#----- Execution -----#
74+
#---------------------#
75+
76+
fn_exists $COMMAND
77+
if [ $? -eq 0 ]; then
78+
$COMMAND $ARGUMENTS
79+
else
80+
usage
81+
fi

src/install/install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
echo "Installing sourcerer app.."
55

6-
SERVER=https://sourcerer.io
7-
DOWNLOAD_URL=$SERVER/download
6+
SERVER=$SERVER_EXT
7+
DOWNLOAD_URL=$SERVER/app/download
88
JAR_DIR=/usr/local/lib
99
SCRIPT_DIR=/usr/local/bin
1010

src/main/kotlin/app/api/ServerApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ServerApi (private val configurator: Configurator) : Api {
5151
}
5252

5353
init {
54-
fuelManager.basePath = BuildConfig.API_BASE_URL
54+
fuelManager.basePath = BuildConfig.API_BASE_PATH
5555
fuelManager.addRequestInterceptor { cookieRequestInterceptor() }
5656
fuelManager.addResponseInterceptor { cookieResponseInterceptor() }
5757
}

0 commit comments

Comments
 (0)