Skip to content

Commit 339efd7

Browse files
authored
Merge pull request #73 from sourcerer-io/develop
release: alpha 0.0.1
2 parents f48c438 + 77fa400 commit 339efd7

Some content is hidden

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

74 files changed

+2394
-604
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
.DS_Store
22
.gradle/
33
.idea/
4+
.sourcerer
45
build/
56
sourcerer-app.iml
67
sourcerer-app.ipr
78
sourcerer-app.iws
9+
app.iml
10+
app.ipr
11+
app.iws
812
/confluence/target
913
/dependencies
1014
/dist
@@ -16,4 +20,5 @@ sourcerer-app.iws
1620
/ultimate/dependencies
1721
/ultimate/ideaSDK
1822
/ultimate/out
19-
/ultimate/tmp
23+
/ultimate/tmp
24+
tmp_repo

build.gradle

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
// Copyright 2017 Sourcerer Inc. All Rights Reserved.
22

33
buildscript {
4-
ext.kotlin_version = '1.1.4-2'
4+
ext.kotlin_version = '1.1.51'
55
repositories {
66
mavenCentral()
77
jcenter()
88
}
99
dependencies {
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.1"
12-
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC2"
11+
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.3"
12+
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.1"
1313
}
1414
}
1515

1616
plugins {
1717
id 'de.fuerstenau.buildconfig' version '1.1.8'
1818
}
1919

20-
21-
2220
apply plugin: "idea"
2321
apply plugin: "java"
2422
apply plugin: "kotlin"
@@ -27,19 +25,11 @@ apply plugin: "com.google.protobuf"
2725
apply plugin: "org.junit.platform.gradle.plugin"
2826

2927
buildConfig {
30-
ext.environment = project.hasProperty('env') &&
31-
env == 'production' ? 'prod' : 'dev'
32-
3328
clsName = 'BuildConfig'
3429
packageName = 'app'
3530

3631
// 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-
32+
def apiBasePath = project.hasProperty('api') ? api : 'https://sourcerer.io/api/commit'
4333
buildConfigField 'String', 'API_BASE_PATH', apiBasePath
4434

4535
// Common.
@@ -49,11 +39,21 @@ buildConfig {
4939
buildConfigField 'int', 'VERSION_CODE', '1'
5040
buildConfigField 'String', 'VERSION', '0.0.1'
5141

42+
// Logging.
43+
buildConfigField 'String', 'LOG_LEVEL', project.hasProperty('log') ? log : 'info'
44+
5245
// Google Analytics.
5346
buildConfigField 'String', 'GA_BASE_PATH', 'http://www.google-analytics.com'
5447
buildConfigField 'String', 'GA_TRACKING_ID', 'UA-107129190-2'
5548
buildConfigField 'boolean', 'IS_GA_ENABLED', 'true'
5649

50+
// Logging.
51+
buildConfigField 'String', 'SENTRY_DSN', 'https://0263d6473bd24a9ba40e25aa5fb0a242:[email protected]/233260'
52+
buildConfigField 'boolean', 'PRINT_STACK_TRACE', 'false'
53+
54+
// Models storage path.
55+
buildConfigField 'String', 'LIBRARY_MODELS_URL', 'https://storage.googleapis.com/sourcerer-app/library-models/v1/'
56+
5757
buildConfig
5858
}
5959

@@ -65,39 +65,49 @@ junitPlatform {
6565
}
6666
}
6767

68+
task cleanData {
69+
delete 'build/libs/data'
70+
delete 'build/kotlin/data'
71+
}
72+
73+
test.dependsOn cleanData
74+
6875
mainClassName = "app.MainKt"
6976

7077
repositories {
7178
mavenCentral()
7279
jcenter()
7380
maven { url "http://dl.bintray.com/jetbrains/spek" }
81+
flatDir {
82+
dirs 'libs'
83+
}
7484
}
7585

7686
dependencies {
7787
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
7888
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
7989
compile "com.beust:jcommander:1.72"
80-
compile 'com.google.protobuf:protobuf-java:3.0.0'
81-
compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
90+
compile 'com.google.protobuf:protobuf-java:3.4.0'
91+
compile 'commons-codec:commons-codec:1.5'
8292
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.9'
8393
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.8.9'
8494
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.9'
85-
compile "io.reactivex.rxjava2:rxjava:2.1.1"
86-
compile 'com.github.kittinunf.fuel:fuel:1.9.0'
87-
compile 'com.github.kittinunf.fuel:fuel-rxjava:1.9.0'
88-
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit',
89-
version: '4.8.0.201706111038-r'
90-
compile "org.slf4j:slf4j-nop:1.7.2"
95+
compile 'io.reactivex.rxjava2:rxjava:2.1.6'
96+
compile 'com.github.kittinunf.fuel:fuel:1.11.0'
97+
compile 'com.github.kittinunf.fuel:fuel-rxjava:1.11.0'
98+
compile 'org.eclipse.jgit:org.eclipse.jgit:4.9.0.201710071750-r'
99+
compile 'org.slf4j:slf4j-nop:1.7.2'
100+
compile 'io.sentry:sentry:1.6.0'
91101

92102
testCompile 'org.jetbrains.kotlin:kotlin-test'
93-
testCompile 'org.jetbrains.spek:spek-api:1.1.4'
94-
testCompile 'org.junit.platform:junit-platform-runner:1.0.0-RC2'
95-
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.4'
103+
testCompile 'org.jetbrains.spek:spek-api:1.1.5'
104+
testCompile 'org.junit.platform:junit-platform-runner:1.0.1'
105+
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
96106
}
97107

98108
protobuf {
99109
protoc {
100-
artifact = "com.google.protobuf:protoc:3.0.0"
110+
artifact = "com.google.protobuf:protoc:3.4.0"
101111
}
102112
}
103113

deploy/Jenkinsfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
podTemplate(label: 'build-pod-sourcerer-app',
22
containers: [
3-
containerTemplate(name: 'jnlp', image: 'gcr.io/cloud-solutions-images/jenkins-k8s-slave', args: '${computer.jnlpmac} ${computer.name}'),
3+
containerTemplate(name: 'jnlp', image: 'gcr.io/sourcerer-1377/jenkins-slave:v4', args: '${computer.jnlpmac} ${computer.name}'),
44
containerTemplate(name: 'gradle', image: 'gcr.io/sourcerer-1377/gradle:4.2.0', ttyEnabled: true, command: 'tail -f /dev/null')
55
],
66
envVars: [
@@ -12,11 +12,15 @@ podTemplate(label: 'build-pod-sourcerer-app',
1212
]
1313
) {
1414
node('build-pod-sourcerer-app') {
15-
def namespace = 'staging'
16-
def benv = 'development'
15+
def namespace = 'sandbox'
16+
def plog = 'debug'
17+
1718
if (env.BRANCH_NAME == 'master') {
18-
benv = 'production'
1919
namespace = 'production'
20+
plog = 'info'
21+
} else if (env.BRANCH_NAME == 'develop') {
22+
namespace = 'staging'
23+
plog = 'info'
2024
}
2125

2226
stage('checkout') {
@@ -25,7 +29,7 @@ podTemplate(label: 'build-pod-sourcerer-app',
2529

2630
stage('build jar and test') {
2731
container('gradle') {
28-
sh("ENV=${benv} ./do.sh build_jar_inside")
32+
sh("LOG=${plog} NAMESPACE=${namespace} ./do.sh build_jar_inside")
2933
}
3034
}
3135

deploy/production_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export REPLICAS="2"

deploy/sandbox_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export REPLICAS="1"

deploy/sourcerer-app-staging.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

deploy/sourcerer-app-production.yaml renamed to deploy/sourcerer-app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ kind: Deployment
1616
metadata:
1717
name: sourcerer-app
1818
spec:
19-
replicas: 2
19+
replicas: $REPLICAS
2020
template:
2121
metadata:
2222
labels:
2323
app: sourcerer-app
2424
spec:
2525
containers:
2626
- name: sourcerer-app
27-
image: gcr.io/sourcerer-1377/sourcerer-app:CONTAINER_TAG
27+
image: gcr.io/sourcerer-1377/sourcerer-app:$CONTAINER_TAG
2828
imagePullPolicy: Always
2929
resources:
3030
requests:

deploy/staging_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export REPLICAS="1"

do.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#----- Helpers -----#
55
#-------------------#
66

7+
set -x
8+
79
usage() {
810
echo "$0 [COMMAND] [ARGUMENTS]"
911
echo " Commands:"
@@ -22,8 +24,8 @@ shift
2224
ARGUMENTS=${@}
2325

2426
TAG="${CONTAINER_TAG:-latest}"
25-
NAMESPACE="${NAMESPACE:-staging}"
26-
ENV="${ENV:-development}"
27+
NAMESPACE="${NAMESPACE:-sandbox}"
28+
LOG="${LOG:-debug}"
2729
VOLUME="${BUILD_VOLUME:-$PWD}"
2830
PROJECT=sourcerer-app
2931
PORT=3182
@@ -36,12 +38,22 @@ GRADLE_VERSION=4.2.0
3638

3739
# run only inside build container
3840
build_jar_inside() {
39-
gradle -Penv=$ENV build
41+
if [ "$NAMESPACE" == "sandbox" ]; then
42+
API="https://sandbox.eng.sourcerer.io/api/commit"
43+
elif [ "$NAMESPACE" == "staging" ]; then
44+
API="https://staging.eng.sourcerer.io/api/commit"
45+
elif [ "$NAMESPACE" == "local" ]; then
46+
API="http://localhost:3181"
47+
else
48+
API="https://sourcerer.io/api/commit"
49+
fi
50+
gradle -Plog=$LOG -Papi=$API build
4051
}
4152

4253
build_jar() {
43-
docker run -i -v $VOLUME:/home/gradle/app --workdir=/home/gradle/app -e ENV=$ENV \
44-
gradle:$GRADLE_VERSION \
54+
docker run -i -v $VOLUME:/home/gradle/app --workdir=/home/gradle/app \
55+
-e LOG=$LOG -e NAMESPACE=$NAMESPACE \
56+
gradle:$GRADLE_VERSION \
4557
./do.sh build_jar_inside
4658
}
4759

@@ -50,7 +62,8 @@ build_prod_inside() {
5062
}
5163

5264
deploy() {
53-
sed "s#CONTAINER_TAG#$TAG#" ./deploy/sourcerer-app-$NAMESPACE.yaml > /tmp/deploy.yaml
65+
source ./deploy/${NAMESPACE}_env.sh
66+
envsubst < ./deploy/sourcerer-app.yaml > /tmp/deploy.yaml
5467
kubectl --namespace=$NAMESPACE apply -f /tmp/deploy.yaml
5568
}
5669

src/install/install

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ echo "Installing sourcerer app.."
55

66
SERVER=$SERVER_EXT
77
DOWNLOAD_URL=$SERVER/app/download
8-
JAR_DIR=/usr/local/lib
9-
SCRIPT_DIR=/usr/local/bin
8+
SCRIPT_DIR=$HOME/.sourcerer
9+
JAR_DIR=$SCRIPT_DIR
1010

1111
if [ -f $SCRIPT_DIR/sourcerer ] ; then
1212
read -p "Previous version of sourcerer is detected. Reinstall it? [Y/n] " yesno < /dev/tty
@@ -16,6 +16,8 @@ if [ -f $SCRIPT_DIR/sourcerer ] ; then
1616
fi
1717
fi
1818

19+
mkdir -p $SCRIPT_DIR
20+
mkdir -p $JAR_DIR
1921
curl -s $DOWNLOAD_URL > $JAR_DIR/sourcerer.jar
2022

2123
cat <<EOF > $SCRIPT_DIR/sourcerer
@@ -27,8 +29,9 @@ if [ "\$1" = "--uninstall" ] ; then
2729
exit
2830
fi
2931

32+
rm -f /usr/local/bin/sourcerer
3033
rm $SCRIPT_DIR/sourcerer
31-
rm $JAR_DIR/sourcerer.jar
34+
rm -r $JAR_DIR
3235

3336
echo "Done!"
3437
exit
@@ -45,10 +48,24 @@ if ! which java > /dev/null ; then
4548
exit 1
4649
fi
4750

48-
java -jar $JAR_DIR/sourcerer.jar "\$@"
51+
# Java 9 requires additional parameters.
52+
version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
53+
if [[ "$version" > "9." ]]; then # Version example for Java 9: 9.0.1
54+
java --add-modules java.activation --add-opens java.base/java.nio=ALL-UNNAMED -jar $JAR_DIR/sourcerer.jar "\$@"
55+
else
56+
java -jar $JAR_DIR/sourcerer.jar "\$@"
57+
fi
4958
EOF
5059

5160
chmod +x $SCRIPT_DIR/sourcerer
5261

53-
echo "Done!"
54-
echo "Run sourcerer to start hashing your repos!"
62+
63+
{
64+
rm -f /usr/local/bin/sourcerer 2> /dev/null &&
65+
ln -s $SCRIPT_DIR/sourcerer /usr/local/bin/sourcerer 2> /dev/null &&
66+
echo "Done!" &&
67+
echo "Run sourcerer to start hashing your repos!"
68+
} || {
69+
echo 'We installed app to $HOME/.sourcerer/sourcerer.'
70+
echo 'You can add it to $PATH or ln it to /usr/local/bin'
71+
}

0 commit comments

Comments
 (0)