Skip to content

Commit 99fd386

Browse files
authored
ci: added CircleCI config + auto-deploy with Docker 🐬 (#4)
* refactor: switched project to Maven * chore: added LWJGL libs in Maven * ci: updated build command with maven * ci: fixed typo in maven apt install * ci: removed maven apt install from build * fix: expose UDP port in Dockerfile
1 parent 881bd84 commit 99fd386

File tree

95 files changed

+328
-893
lines changed

Some content is hidden

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

95 files changed

+328
-893
lines changed

.circleci/config.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ version: 2.1
33
executors:
44
docker-executor:
55
docker:
6-
- image: circleci/openjdk:17-jdk
6+
- image: cimg/openjdk:21.0.2
77

88
jobs:
99
build:
1010
executor: docker-executor
1111
steps:
12-
- build
12+
- checkout
13+
- run:
14+
name: Install APT dependencies
15+
command: |
16+
sudo apt update
17+
sudo apt install -y findutils
1318
- run:
1419
name: Build server application
1520
command: |
16-
mkdir -p build/libs
17-
javac -cp 'libs/*' -d build/classes $(find src -name '*.java')
18-
jar --create --file build/libs/MinecraftServer.jar --manifest < (echo "Main-Class: fr.math.minecraft.ServerMain") -C build/classes .
19-
jar --update --file build/libs/MinecraftServer.jar -C libs .
21+
mvn clean package
2022
2123
deploy:
2224
executor: docker-executor
2325
steps:
2426
- run:
2527
name: Install SSH Client
2628
command: |
27-
apt-get update && apt-get install -y openssh-client
29+
sudo apt-get update && sudo apt-get install -y openssh-client
30+
- run:
31+
name: Add VPS host to known hosts
32+
command: |
33+
mkdir -p ~/.ssh
34+
ssh-keyscan -p $PORT -H $HOST >> ~/.ssh/known_hosts
2835
- run:
2936
name: Deploy application
3037
command: |
31-
echo "Host $HOST" >> ~/.ssh/config
32-
echo " User $USERNAME" >> ~/.ssh/config
33-
echo " Port $PORT" >> ~/.ssh/config
34-
echo " PasswordAuthentication yes" >> ~/.ssh/config
35-
echo " PubkeyAuthentication no" >> ~/.ssh/config
36-
37-
sshpass -p $PASSWORD scp build/libs/MinecraftServer.jar $USERNAME@$HOST:/opt/Minecraft_Clone/
38-
sshpass -p $PASSWORD ssh $USERNAME@$HOST 'docker stop minecraft-clone-server || true && docker rm minecraft-clone-server || true && docker run -d -p 50000:50000 -v /opt/Minecraft_Clone:/app --name minecraft-clone-server openjdk:17-jdk-slim java -jar /app/MinecraftServer.jar'
38+
ssh $USERNAME@$HOST -p $PORT 'cd /opt/Minecraft_Clone && sh /opt/Minecraft_Clone/deploy.sh'
3939
4040
workflows:
4141
version: 2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ bin/
2929

3030
### Mac OS ###
3131
.DS_Store
32+
33+
## Game
34+
target/
3235
src/log/client-log.txt
3336
src/log/client-log.txt
3437
src/log/

Dockerfile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ FROM openjdk:17-jdk-slim AS builder
22
WORKDIR /build
33

44
COPY src ./src
5-
COPY libs ./libs
6-
7-
RUN javac -cp 'libs/linux/*' -d out $(find src -name '*.java')
8-
9-
RUN jar --create --file MinecraftServer.jar --manifest /dev/null -C out .
10-
RUN echo "Main-Class: fr.math.minecraft.ServerMain" > MANIFEST.MF && jar --update --file MinecraftServer.jar --manifest MANIFEST.MF
11-
RUN jar --update --file MinecraftServer.jar -C libs .
5+
COPY pom.xml ./pom.xml
126

7+
RUN apt-get update && apt-get install -y maven
8+
RUN mvn clean package
139

1410
FROM openjdk:17-jdk-slim
1511
WORKDIR /app
1612

17-
COPY --from=builder /build/MinecraftServer.jar .
13+
COPY log ./log
14+
COPY --from=builder /build/target/minecraft-clone-1.0-SNAPSHOT-jar-with-dependencies.jar .
1815

19-
EXPOSE 50000
16+
EXPOSE 50000/udp
2017

21-
CMD ["java", "-jar", "MinecraftServer.jar"]
18+
CMD ["java", "-jar", "minecraft-clone-1.0-SNAPSHOT-jar-with-dependencies.jar"]

libs/hamcrest-core-1.3.jar

-44 KB
Binary file not shown.
-74.3 KB
Binary file not shown.

libs/jackson-core-2.14.1.jar

-449 KB
Binary file not shown.

libs/jackson-databind-2.14.1.jar

-1.54 MB
Binary file not shown.

libs/junit-4.11.jar

-239 KB
Binary file not shown.

libs/linux/LICENSE

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

libs/linux/assimp_license.txt

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

0 commit comments

Comments
 (0)