Skip to content

Commit

Permalink
docker (#142)
Browse files Browse the repository at this point in the history
* docker
  • Loading branch information
jxnu-liguobin authored May 19, 2022
1 parent 59de7d5 commit 54f8f1f
Show file tree
Hide file tree
Showing 11 changed files with 944 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git/
target/
project/project
project/target
application.conf.example
logs
.idea
17 changes: 16 additions & 1 deletion .github/workflows/ScalaCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ jobs:

- name: Checking headers
run: sbt headerCheckAll

docker:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [ 8 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java-version }}

- name: Build Image
run: sbt docker:publishLocal

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,7 +77,7 @@ jobs:

ci:
runs-on: ubuntu-latest
needs: [ build, test ]
needs: [ build, docker, test ]
steps:
- name: Aggregate outcomes
run: echo "build succeeded"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

[在线预览地址](http://im.dreamylost.cn:8989)

[完整Docker镜像](https://hub.docker.com/r/liguobin/zim/tags)

**如果感兴趣可以watch一下,如果对你有帮助可以点个star,欢迎贡献。**

## 模块
Expand All @@ -22,6 +24,7 @@
- java 8/11
- redis 4/5/6
- mysql 8
- docker-compose

## 技术栈

Expand Down
40 changes: 25 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@ ThisBuild / resolvers ++= Seq(
"New snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots/"
)

lazy val assemblySettings = Seq(
ThisBuild / assemblyMergeStrategy := {
case "application.conf" => MergeStrategy.concat
case x if x.endsWith(".txt") || x.endsWith(".proto") => MergeStrategy.first
case x if x.endsWith("module-info.class") => MergeStrategy.first
case x if x.endsWith(".properties") => MergeStrategy.deduplicate
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}
)
// sbt-assembly, not support build docker image by sbt task, so we use sbt-native-packager
//lazy val assemblySettings = Seq(
// ThisBuild / assemblyMergeStrategy := {
// case "application.conf" => MergeStrategy.concat
// case x if x.endsWith(".txt") || x.endsWith(".proto") => MergeStrategy.first
// case x if x.endsWith("module-info.class") => MergeStrategy.first
// case x if x.endsWith(".properties") => MergeStrategy.deduplicate
// case x =>
// val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
// oldStrategy(x)
// }
//)

lazy val commonConfiguration: Project => Project =
_.settings(Information.value)
.settings(ProjectSetting.value)
.settings(ProjectSetting.noPublish)
.settings(commands ++= Commands.value)
.settings(assemblySettings)
// .settings(assemblySettings)
.settings(
semanticdbEnabled := true, // enable SemanticDB
semanticdbVersion := scalafixSemanticdb.revision,
Expand All @@ -61,11 +62,20 @@ lazy val zim = (project in file("."))
lazy val `zim-server` = (project in file("modules/zim-server"))
.settings(
libraryDependencies ++= Dependencies.serverDeps,
Compile / scalacOptions ++= List("-Ymacro-annotations")
Compile / scalacOptions ++= List("-Ymacro-annotations"),
Docker / packageName := "liguobin/zim",
Docker / version := version.value,
dockerBaseImage := "openjdk",
dockerExposedVolumes ++= Seq("/opt/docker"),
dockerExposedPorts := Seq(9000),
Compile / mainClass := Some("org.bitlap.zim.server.ZimServer"),
dockerEntrypoint := Seq(
"/opt/docker/bin/zim-server" ,"--privileged=true"
)
)
.settings(assembly / mainClass := Some("org.bitlap.zim.server.ZimServer"))
// .settings(assembly / mainClass := Some("org.bitlap.zim.server.ZimServer"))
.configure(commonConfiguration)
.enablePlugins(ScalafmtPlugin, HeaderPlugin)
.enablePlugins(ScalafmtPlugin, HeaderPlugin, JavaServerAppPackaging, DockerPlugin)
.dependsOn(`zim-cache`, `zim-api`, `zim-auth`, `zim-infra`)

lazy val `zim-infra` = (project in file("modules/zim-infra"))
Expand Down
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
zim_server:
image: liguobin/zim:0.3.0-SNAPSHOT
container_name: zim_server
depends_on:
- zim_mysql_server
- zim_redis_server
ports:
- "9000:9000"

zim_mysql_server:
image: mysql:oracle
restart: always
container_name: zim_mysql_server
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
ports:
- "3306:3306"
# FIXME The MySQL host directory must already exist, change it to your own MySQL location
volumes:
- /opt/homebrew/var/mysql/datadir:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- MYSQL_DATABASE=trace
- MYSQL_ALLOW_EMPTY_PASSWORD=yes

zim_redis_server:
image: redis
container_name: zim_redis_server
command: redis-server
restart: always
ports:
- "6379:6379"
30 changes: 30 additions & 0 deletions docker-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# it only executed for local pc, and used local image
IFS=$'\n'
maybeOld=`docker ps | grep liguobin/zim | awk '{print $1}'`
if [[ -n "$maybeOld" ]];then
for line in `cat version.sbt`
do
docker image rm liguobin/zim:$line -f
done
fi


sbt docker:publishLocal

fold=`pwd`

cd /opt/homebrew/var/mysql/datadir/

rm -rf ./*

cd $fold

docker-compose -f docker-compose.yml up -d

zim_container_ip=`docker ps | grep liguobin/zim | awk '{print $1}' | xargs docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'`
echo "zim server container ip: $zim_container_ip"


# mac osx visit docker container network? see https://www.haoyizebo.com/posts/fd0b9bd8/ and close your VPN
Loading

0 comments on commit 54f8f1f

Please sign in to comment.