This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/skywalking-showcase.git
commit b61453fc5e4a0c43e65014463a22c7cfb3006f7e Author: kezhenxu94 <[email protected]> AuthorDate: Wed Oct 27 21:57:04 2021 +0800 Set up gateway and songs service and deploy platform docker --- .gitignore | 37 +++++++- Makefile | 20 ++++ deploy/platform/docker/.env | 3 + deploy/platform/docker/Makefile | 13 +++ deploy/platform/docker/docker-compose.yaml | 104 +++++++++++++++++++++ .../{song-service => gateway-service}/Dockerfile | 12 +-- .../{song-service => gateway-service}/Makefile | 6 +- services/gateway-service/build.gradle | 32 +++++++ .../gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.jar | Bin .../gradle}/wrapper/gradle-wrapper.properties | 2 +- services/{song-service => gateway-service}/gradlew | 17 ---- .../{song-service => gateway-service}/gradlew.bat | 17 ---- services/gateway-service/settings.gradle | 1 + .../showcase/gateway/GatewayApplication.java | 13 +++ .../src/main/resources/application.yaml | 12 +++ .../showcase/gateway/GatewayApplicationTests.java | 13 +++ services/recommendation-service/build.gradle | 6 -- services/song-service/settings.gradle | 24 ----- .gitignore => services/songs-service/Dockerfile | 12 +-- services/{song-service => songs-service}/Makefile | 6 +- .../{song-service => songs-service}/build.gradle | 3 +- .../gradle.properties | 0 .../gradle}/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 0 services/{song-service => songs-service}/gradlew | 0 .../{song-service => songs-service}/gradlew.bat | 0 .../settings.gradle} | 2 + .../services/song/SongServiceApplication.java | 0 .../services/song/controller/SongController.java | 0 .../showcase/services/song/entity/Song.java | 0 .../showcase/services/song/repo/SongsRepo.java | 0 .../src/main/resources/application.yaml | 3 +- .../src/main/resources/data.sql | 0 .../song/JavaServicesApplicationTests.java | 0 35 files changed, 265 insertions(+), 93 deletions(-) diff --git a/.gitignore b/.gitignore index d425778..b14baaa 100644 --- a/.gitignore +++ b/.gitignore @@ -21,9 +21,42 @@ # Ignore Gradle build output directory build +.venv + +.DS_Store + +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### .idea +*.iws *.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ -.venv +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ -.DS_Store +### VS Code ### +.vscode/ diff --git a/Makefile b/Makefile index a4c0b62..afe2e86 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,23 @@ # under the License. # +.PHONY: build +build: + $(MAKE) -C services/gateway-service build + $(MAKE) -C services/songs-service build + +.PHONY: docker +docker: docker.build + +.PHONY: docker.build +docker.build: + $(MAKE) -C services/gateway-service docker.build + $(MAKE) -C services/songs-service docker.build + +.PHONY: deploy.docker +deploy.docker: undeploy.docker docker.build + $(MAKE) -C deploy/platform/docker deploy + +.PHONY: undeploy.docker +undeploy.docker: + $(MAKE) -C deploy/platform/docker undeploy diff --git a/deploy/platform/docker/.env b/deploy/platform/docker/.env new file mode 100644 index 0000000..977da00 --- /dev/null +++ b/deploy/platform/docker/.env @@ -0,0 +1,3 @@ +ES_VERSION=7.10.0 +OAP_IMAGE=ghcr.io/apache/skywalking/oap:c9bd79e8bb974e404766e3490c00c7404b9baf1e +ROCKET_BOT_IMAGE=ghcr.io/apache/skywalking/ui:c9bd79e8bb974e404766e3490c00c7404b9baf1e diff --git a/deploy/platform/docker/Makefile b/deploy/platform/docker/Makefile new file mode 100644 index 0000000..06547b7 --- /dev/null +++ b/deploy/platform/docker/Makefile @@ -0,0 +1,13 @@ +include ../../../Makefile.in + +.PHONY: deploy +deploy: + export HUB=$(HUB); \ + export TAG=$(TAG); \ + docker-compose up -d + +.PHONY: undeploy +undeploy: + export HUB=$(HUB); \ + export TAG=$(TAG); \ + docker-compose down diff --git a/deploy/platform/docker/docker-compose.yaml b/deploy/platform/docker/docker-compose.yaml new file mode 100644 index 0000000..201a8d6 --- /dev/null +++ b/deploy/platform/docker/docker-compose.yaml @@ -0,0 +1,104 @@ +version: '2.1' + +services: + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch-oss:${ES_VERSION} + networks: [ sw ] + ports: + - "9200:9200" + healthcheck: + test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health" ] + interval: 30s + timeout: 10s + retries: 3 + environment: + - discovery.type=single-node + - bootstrap.memory_lock=true + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ulimits: + memlock: + soft: -1 + hard: -1 + + oap: + image: ${OAP_IMAGE} + networks: [ sw ] + environment: + SW_HEALTH_CHECKER: default + SW_TELEMETRY: prometheus + SW_STORAGE: elasticsearch + SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200 + JAVA_OPTS: "-Xms2048m -Xmx2048m" + healthcheck: + test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ] + interval: 30s + timeout: 10s + retries: 3 + depends_on: + elasticsearch: + condition: service_healthy + + rocket-bot: + image: ${ROCKET_BOT_IMAGE} + networks: [ sw ] + ports: + - "9999:8080" + depends_on: + oap: + condition: service_healthy + environment: + SW_OAP_ADDRESS: http://oap:12800 + + gateway: + image: ${HUB}/gateway-service:${TAG} + networks: [ sw ] + environment: + SW_AGENT_NAME: gateway + SW_AGENT_COLLECTOR_BACKEND_SERVICES: oap:11800 + ports: + - "7389:80" + healthcheck: + test: [ "CMD-SHELL", "wget http://localhost/actuator/health" ] + interval: 30s + timeout: 10s + retries: 3 + depends_on: + oap: + condition: service_healthy + songs: + condition: service_healthy + + songs: + image: ${HUB}/songs-service:${TAG} + networks: [ sw ] + environment: + SW_AGENT_NAME: songs + SW_AGENT_COLLECTOR_BACKEND_SERVICES: oap:11800 + ports: + - "7390:80" + healthcheck: + test: [ "CMD-SHELL", "wget http://localhost/actuator/health" ] + interval: 30s + timeout: 10s + retries: 3 + depends_on: + oap: + condition: service_healthy + + loadgen: + image: curlimages/curl + networks: [ sw ] + depends_on: + gateway: + condition: service_healthy + entrypoint: + - sh + - -c + - | + while true; do + curl http://gateway/songs + sleep 3 + done + +networks: + sw: diff --git a/services/song-service/Dockerfile b/services/gateway-service/Dockerfile similarity index 80% rename from services/song-service/Dockerfile rename to services/gateway-service/Dockerfile index 48e26d5..f0e4c97 100644 --- a/services/song-service/Dockerfile +++ b/services/gateway-service/Dockerfile @@ -16,16 +16,10 @@ # under the License. # -FROM ghcr.io/apache/skywalking-java/jdk-11:latest as build - -COPY . /workspace - -WORKDIR /workspace - -RUN ./gradlew build - FROM ghcr.io/apache/skywalking-java/jdk-11:latest -COPY --from=build /workspace/build/libs/skywalking-showcase-0.0.1-SNAPSHOT.jar /app.jar +COPY build/libs/gateway-service-0.0.1-SNAPSHOT.jar /app.jar + +RUN mv /skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-*.jar /skywalking/agent/plugins/ CMD ["java", "-jar", "/app.jar"] diff --git a/services/song-service/Makefile b/services/gateway-service/Makefile similarity index 89% copy from services/song-service/Makefile copy to services/gateway-service/Makefile index 47f6405..079ba96 100644 --- a/services/song-service/Makefile +++ b/services/gateway-service/Makefile @@ -28,8 +28,8 @@ clean: docker: docker.push -docker.build: clean - docker build . -t $(HUB)/song-service:$(TAG) +docker.build: build + docker build . -t $(HUB)/gateway-service:$(TAG) docker.push: docker.build - docker push $(HUB)/song-service:$(TAG) + docker push $(HUB)/gateway-service:$(TAG) diff --git a/services/gateway-service/build.gradle b/services/gateway-service/build.gradle new file mode 100644 index 0000000..555a111 --- /dev/null +++ b/services/gateway-service/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'org.springframework.boot' version '2.5.6' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' +} + +group = 'org.apache.skywalking.showcase.services.gateway' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +ext { + set('springCloudVersion', "2020.0.4") +} + +dependencies { + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + +test { + useJUnitPlatform() +} diff --git a/services/song-service/gradle.properties b/services/gateway-service/gradle.properties similarity index 100% copy from services/song-service/gradle.properties copy to services/gateway-service/gradle.properties diff --git a/services/song-service/gradle/wrapper/gradle-wrapper.jar b/services/gateway-service/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from services/song-service/gradle/wrapper/gradle-wrapper.jar rename to services/gateway-service/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/services/gateway-service/gradle/wrapper/gradle-wrapper.properties similarity index 93% rename from gradle/wrapper/gradle-wrapper.properties rename to services/gateway-service/gradle/wrapper/gradle-wrapper.properties index 69a9715..ffed3a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/services/gateway-service/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/services/song-service/gradlew b/services/gateway-service/gradlew similarity index 91% copy from services/song-service/gradlew copy to services/gateway-service/gradlew index 4f0eb25..1b6c787 100755 --- a/services/song-service/gradlew +++ b/services/gateway-service/gradlew @@ -1,21 +1,4 @@ #!/bin/sh -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# # # Copyright © 2015-2021 the original authors. diff --git a/services/song-service/gradlew.bat b/services/gateway-service/gradlew.bat old mode 100755 new mode 100644 similarity index 76% copy from services/song-service/gradlew.bat copy to services/gateway-service/gradlew.bat index a74be7b..107acd3 --- a/services/song-service/gradlew.bat +++ b/services/gateway-service/gradlew.bat @@ -1,20 +1,3 @@ -rem Licensed to the Apache Software Foundation (ASF) under one -rem or more contributor license agreements. See the NOTICE file -rem distributed with this work for additional information -rem regarding copyright ownership. The ASF licenses this file -rem to you under the Apache License, Version 2.0 (the -rem "License"); you may not use this file except in compliance -rem with the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, -rem software distributed under the License is distributed on an -rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -rem KIND, either express or implied. See the License for the -rem specific language governing permissions and limitations -rem under the License. -rem @rem @rem Copyright 2015 the original author or authors. @rem diff --git a/services/gateway-service/settings.gradle b/services/gateway-service/settings.gradle new file mode 100644 index 0000000..d0b38d1 --- /dev/null +++ b/services/gateway-service/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gateway-service' diff --git a/services/gateway-service/src/main/java/org/apache/skywalking/showcase/gateway/GatewayApplication.java b/services/gateway-service/src/main/java/org/apache/skywalking/showcase/gateway/GatewayApplication.java new file mode 100644 index 0000000..1fe6ce5 --- /dev/null +++ b/services/gateway-service/src/main/java/org/apache/skywalking/showcase/gateway/GatewayApplication.java @@ -0,0 +1,13 @@ +package org.apache.skywalking.showcase.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + +} diff --git a/services/gateway-service/src/main/resources/application.yaml b/services/gateway-service/src/main/resources/application.yaml new file mode 100644 index 0000000..582dff9 --- /dev/null +++ b/services/gateway-service/src/main/resources/application.yaml @@ -0,0 +1,12 @@ +server: + port: 80 + address: 0.0.0.0 + +spring: + cloud: + gateway: + routes: + - id: songs-service + uri: http://songs + predicates: + - Path=/songs/** diff --git a/services/gateway-service/src/test/java/org/apache/skywalking/showcase/gateway/GatewayApplicationTests.java b/services/gateway-service/src/test/java/org/apache/skywalking/showcase/gateway/GatewayApplicationTests.java new file mode 100644 index 0000000..e8e43b9 --- /dev/null +++ b/services/gateway-service/src/test/java/org/apache/skywalking/showcase/gateway/GatewayApplicationTests.java @@ -0,0 +1,13 @@ +package org.apache.skywalking.showcase.gateway; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GatewayApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/services/recommendation-service/build.gradle b/services/recommendation-service/build.gradle deleted file mode 100644 index 6684127..0000000 --- a/services/recommendation-service/build.gradle +++ /dev/null @@ -1,6 +0,0 @@ -afterEvaluate { - exec { - commandLine 'python3', '-m', 'venv', '.venv' - ignoreExitValue true - } -} diff --git a/services/song-service/settings.gradle b/services/song-service/settings.gradle deleted file mode 100644 index d877293..0000000 --- a/services/song-service/settings.gradle +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -rootProject.name = 'skywalking-showcase' - -include 'services:song-service' -include 'services:recommendation-service' - diff --git a/.gitignore b/services/songs-service/Dockerfile similarity index 84% copy from .gitignore copy to services/songs-service/Dockerfile index d425778..28c4938 100644 --- a/.gitignore +++ b/services/songs-service/Dockerfile @@ -15,15 +15,9 @@ # specific language governing permissions and limitations # under the License. # -# Ignore Gradle project-specific cache directory -.gradle -# Ignore Gradle build output directory -build +FROM ghcr.io/apache/skywalking-java/jdk-11:latest -.idea -*.iml +COPY build/libs/songs-service-0.0.1-SNAPSHOT.jar /app.jar -.venv - -.DS_Store +CMD ["java", "-jar", "/app.jar"] diff --git a/services/song-service/Makefile b/services/songs-service/Makefile similarity index 90% rename from services/song-service/Makefile rename to services/songs-service/Makefile index 47f6405..d3502af 100644 --- a/services/song-service/Makefile +++ b/services/songs-service/Makefile @@ -28,8 +28,8 @@ clean: docker: docker.push -docker.build: clean - docker build . -t $(HUB)/song-service:$(TAG) +docker.build: build + docker build . -t $(HUB)/songs-service:$(TAG) docker.push: docker.build - docker push $(HUB)/song-service:$(TAG) + docker push $(HUB)/songs-service:$(TAG) diff --git a/services/song-service/build.gradle b/services/songs-service/build.gradle similarity index 92% rename from services/song-service/build.gradle rename to services/songs-service/build.gradle index c88e4f4..8cc1ad2 100644 --- a/services/song-service/build.gradle +++ b/services/songs-service/build.gradle @@ -23,7 +23,7 @@ plugins { id 'java' } -group = 'org.apache.skywalking.showcase.services.java' +group = 'org.apache.skywalking.showcase.services.song' version = '0.0.1-SNAPSHOT' configurations { @@ -39,6 +39,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.kafka:spring-kafka' implementation 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' diff --git a/services/song-service/gradle.properties b/services/songs-service/gradle.properties similarity index 100% rename from services/song-service/gradle.properties rename to services/songs-service/gradle.properties diff --git a/gradle/wrapper/gradle-wrapper.jar b/services/songs-service/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from gradle/wrapper/gradle-wrapper.jar rename to services/songs-service/gradle/wrapper/gradle-wrapper.jar diff --git a/services/song-service/gradle/wrapper/gradle-wrapper.properties b/services/songs-service/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from services/song-service/gradle/wrapper/gradle-wrapper.properties rename to services/songs-service/gradle/wrapper/gradle-wrapper.properties diff --git a/services/song-service/gradlew b/services/songs-service/gradlew similarity index 100% rename from services/song-service/gradlew rename to services/songs-service/gradlew diff --git a/services/song-service/gradlew.bat b/services/songs-service/gradlew.bat similarity index 100% rename from services/song-service/gradlew.bat rename to services/songs-service/gradlew.bat diff --git a/services/build.gradle b/services/songs-service/settings.gradle similarity index 95% rename from services/build.gradle rename to services/songs-service/settings.gradle index 04818b5..e71a0c5 100644 --- a/services/build.gradle +++ b/services/songs-service/settings.gradle @@ -17,3 +17,5 @@ * under the License. * */ +rootProject.name = 'songs-service' + diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java b/services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java similarity index 100% rename from services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java rename to services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java b/services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java similarity index 100% rename from services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java rename to services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java b/services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java similarity index 100% rename from services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java rename to services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java b/services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java similarity index 100% rename from services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java rename to services/songs-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java diff --git a/services/song-service/src/main/resources/application.yaml b/services/songs-service/src/main/resources/application.yaml similarity index 96% rename from services/song-service/src/main/resources/application.yaml rename to services/songs-service/src/main/resources/application.yaml index 92fbf21..29835e0 100644 --- a/services/song-service/src/main/resources/application.yaml +++ b/services/songs-service/src/main/resources/application.yaml @@ -16,7 +16,8 @@ # under the License. # server: - port: 8081 + port: 80 + address: 0.0.0.0 spring: jpa: diff --git a/services/song-service/src/main/resources/data.sql b/services/songs-service/src/main/resources/data.sql similarity index 100% rename from services/song-service/src/main/resources/data.sql rename to services/songs-service/src/main/resources/data.sql diff --git a/services/song-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java b/services/songs-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java similarity index 100% rename from services/song-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java rename to services/songs-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java
