Skip to content

Commit

Permalink
Merge pull request acmcsufoss#17 from acmcsufoss/gradle-build
Browse files Browse the repository at this point in the history
Gradle+Docker Streamline
  • Loading branch information
jjoeldaniel authored Feb 1, 2023
2 parents fa95c8c + 0348eff commit 64d15c1
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 21 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ out/
### Gradle ###
.gradle
build/
gradlew
gradlew.bat

# Ignore Gradle wrapper jar file
gradle-wrapper.jar
!gradle-wrapper.jar

# Manifest MF
*.MF

# Bin folder
bin/
bin/
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM amazoncorretto:19

ADD triggers-1.0-SNAPSHOT-all.jar triggers-1.0-SNAPSHOT-all.jar
COPY triggers.jar triggers.jar

ENTRYPOINT ["java", "-jar", "triggers.jar"]

ENTRYPOINT ["java", "-jar", "triggers-1.0-SNAPSHOT-all.jar"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
1. Build the project

```gradle
gradle build
python3 build.py
```

2. Run the project

```terminal
java -jar .\triggers-1.0-SNAPSHOT-all.jar
java -jar triggers.jar
```

3. To invite your bot,
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ version '1.0-SNAPSHOT'
mainClassName = 'com.acmcsuf.triggers.Bot'

shadowJar {
archiveBaseName = 'triggers'
archiveVersion = ''
archiveClassifier = ''
destinationDirectory.set(file("."))
}

tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

repositories {
mavenCentral()
}
Expand All @@ -21,6 +29,8 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'

implementation 'io.github.cdimascio:dotenv-java:2.3.2'

implementation 'org.slf4j:slf4j-api:2.0.4'

implementation 'org.slf4j:slf4j-simple:2.0.4'
Expand Down
81 changes: 81 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import platform
import subprocess
import argparse

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

# Parse arguments
parser = argparse.ArgumentParser(
description='Builds the project and creates a docker image',
exit_on_error=True
)

parser.add_argument(
'-d',
'--docker',
action='store_true',
help='Builds the docker image'
)

args = parser.parse_args()

# Clean root jars
# Reason: `gradle clean` does not remove the jar files in the root directory
for file in os.listdir('.'):
if file.endswith('.jar'):
os.remove(file)

windows = platform.system() == 'Windows'

# Clean and build jar
if windows:
os.system('.\\gradlew clean')
os.system('.\\gradlew build')
else:
os.system('./gradlew clean')
os.system('./gradlew build')

version = None

# Select version number from build.gradle
with open('build.gradle', 'r') as f:
for line in f:
if 'version' in line:
version = line.split('\'')[1].strip()

# Check if Docker should be built
if args.docker:

if version is None or version == '':
version = 'latest'

print('\n' + bcolors.WARNING + '=' * 50)
print(bcolors.BOLD + '[WARNING]\n' + bcolors.ENDC + bcolors.WARNING)
print('Could not find version number in build.gradle')
print(f'Defaulting to `{version}`')
print('=' * 50 + bcolors.ENDC + '\n')

decision = input('Continue? [y/n]: ').strip().lower()
while decision != 'y' and decision != 'n':

if decision == 'n':
quit()
elif decision == 'y':
os.system(f'docker build -t triggers:{version} .')
break
else:
decision = input()
continue
else:
os.system(f'docker build -t triggers:{version} .')

1 change: 1 addition & 0 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ com.fasterxml.jackson:jackson-bom:2.13.2=runtimeClasspath,testRuntimeClasspath
com.neovisionaries:nv-websocket-client:2.14=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.squareup.okhttp3:okhttp:4.9.3=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.squareup.okio:okio:2.8.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.github.cdimascio:dotenv-java:2.3.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
me.xdrop:fuzzywuzzy:1.4.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.dv8tion:JDA:5.0.0-beta.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.sf.trove4j:trove4j:3.0.3=runtimeClasspath,testRuntimeClasspath
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 64d15c1

Please sign in to comment.