Skip to content

Commit

Permalink
init helm chart for configservice, adminservice and portal
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Jun 27, 2020
1 parent bf1323b commit 885e461
Show file tree
Hide file tree
Showing 34 changed files with 1,295 additions and 184 deletions.
37 changes: 21 additions & 16 deletions apollo-adminservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>*.zip</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
Expand All @@ -132,6 +116,27 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<imageName>apolloconfig/${project.artifactId}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<serverId>docker-hub</serverId>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>*.zip</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 5 additions & 10 deletions apollo-adminservice/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Dockerfile for apollo-adminservice
# 1. Copy apollo-adminservice-${VERSION}-github.zip to current directory
# 2. Build with: docker build -t apollo-adminservice .
# 3. Run with: docker run -p 8090:8090 -e DS_URL="jdbc:mysql://fill-in-the-correct-server:3306/ApolloConfigDB?characterEncoding=utf8" -e DS_USERNAME=FillInCorrectUser -e DS_PASSWORD=FillInCorrectPassword -d -v /tmp/logs:/opt/logs --name apollo-adminservice apollo-adminservice
# 1. ./scripts/build.sh
# 2. Build with: mvn docker:build -pl apollo-adminservice
# 3. Run with: docker run -p 8090:8090 -e SPRING_DATASOURCE_URL="jdbc:mysql://fill-in-the-correct-server:3306/ApolloConfigDB?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=FillInCorrectUser -e SPRING_DATASOURCE_PASSWORD=FillInCorrectPassword -d -v /tmp/logs:/opt/logs --name apollo-adminservice apolloconfig/apollo-adminservice

FROM openjdk:8-jre-alpine
MAINTAINER ameizi <[email protected]>

ENV APOLLO_RUN_MODE "Docker"
ENV VERSION 1.7.0-SNAPSHOT
ENV SERVER_PORT 8090
# DataSource Info
ENV DS_URL ""
ENV DS_USERNAME ""
ENV DS_PASSWORD ""

RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \
&& echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \
Expand All @@ -24,9 +21,7 @@ ADD apollo-adminservice-${VERSION}-github.zip /apollo-adminservice/apollo-admins

RUN unzip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip -d /apollo-adminservice \
&& rm -rf /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip \
&& sed -i '$d' /apollo-adminservice/scripts/startup.sh \
&& chmod +x /apollo-adminservice/scripts/startup.sh \
&& echo "tail -f /dev/null" >> /apollo-adminservice/scripts/startup.sh
&& chmod +x /apollo-adminservice/scripts/startup.sh

EXPOSE $SERVER_PORT

Expand Down
69 changes: 37 additions & 32 deletions apollo-adminservice/src/main/scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,46 +116,51 @@ if [[ ! -f PATH_TO_JAR && -d current ]]; then
done
fi

if [[ -f $SERVICE_NAME".jar" ]]; then
rm -rf $SERVICE_NAME".jar"
fi
# For Docker environment, start in foreground mode
if [[ -n "$APOLLO_RUN_MODE" ]] && [[ "$APOLLO_RUN_MODE" == "Docker" ]]; then
$javaexe -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar $PATH_TO_JAR
else
if [[ -f $SERVICE_NAME".jar" ]]; then
rm -rf $SERVICE_NAME".jar"
fi

printf "$(date) ==== Starting ==== \n"
printf "$(date) ==== Starting ==== \n"

ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start
ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start

rc=$?;
rc=$?;

if [[ $rc != 0 ]];
then
echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
exit $rc;
fi
if [[ $rc != 0 ]];
then
echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
exit $rc;
fi

declare -i counter=0
declare -i max_counter=48 # 48*5=240s
declare -i total_time=0
declare -i counter=0
declare -i max_counter=48 # 48*5=240s
declare -i total_time=0

printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
sleep 5
printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
sleep 5

checkPidAlive
done
checkPidAlive
done

total_time=counter*5
total_time=counter*5

if [[ (( counter -ge max_counter )) ]];
then
printf "\n$(date) Server failed to start in $total_time seconds!\n"
exit 1;
fi
if [[ (( counter -ge max_counter )) ]];
then
printf "\n$(date) Server failed to start in $total_time seconds!\n"
exit 1;
fi

printf "\n$(date) Server started in $total_time seconds!\n"
printf "\n$(date) Server started in $total_time seconds!\n"

exit 0;
exit 0;
fi
37 changes: 21 additions & 16 deletions apollo-configservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,6 @@
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>*.zip</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
Expand All @@ -138,6 +122,27 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<imageName>apolloconfig/${project.artifactId}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<serverId>docker-hub</serverId>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>*.zip</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 5 additions & 10 deletions apollo-configservice/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Dockerfile for apollo-configservice
# 1. Copy apollo-configservice-${VERSION}-github.zip to current directory
# 2. Build with: docker build -t apollo-configservice .
# 3. Run with: docker run -p 8080:8080 -e DS_URL="jdbc:mysql://fill-in-the-correct-server:3306/ApolloConfigDB?characterEncoding=utf8" -e DS_USERNAME=FillInCorrectUser -e DS_PASSWORD=FillInCorrectPassword -d -v /tmp/logs:/opt/logs --name apollo-configservice apollo-configservice
# 1. ./scripts/build.sh
# 2. Build with: mvn docker:build -pl apollo-configservice
# 3. Run with: docker run -p 8080:8080 -e SPRING_DATASOURCE_URL="jdbc:mysql://fill-in-the-correct-server:3306/ApolloConfigDB?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=FillInCorrectUser -e SPRING_DATASOURCE_PASSWORD=FillInCorrectPassword -d -v /tmp/logs:/opt/logs --name apollo-configservice apolloconfig/apollo-configservice

FROM openjdk:8-jre-alpine
MAINTAINER ameizi <[email protected]>

ENV APOLLO_RUN_MODE "Docker"
ENV VERSION 1.7.0-SNAPSHOT
ENV SERVER_PORT 8080
# DataSource Info
ENV DS_URL ""
ENV DS_USERNAME ""
ENV DS_PASSWORD ""

RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \
&& echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \
Expand All @@ -24,9 +21,7 @@ ADD apollo-configservice-${VERSION}-github.zip /apollo-configservice/apollo-conf

RUN unzip /apollo-configservice/apollo-configservice-${VERSION}-github.zip -d /apollo-configservice \
&& rm -rf /apollo-configservice/apollo-configservice-${VERSION}-github.zip \
&& sed -i '$d' /apollo-configservice/scripts/startup.sh \
&& chmod +x /apollo-configservice/scripts/startup.sh \
&& echo "tail -f /dev/null" >> /apollo-configservice/scripts/startup.sh
&& chmod +x /apollo-configservice/scripts/startup.sh

EXPOSE $SERVER_PORT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

@EnableAspectJAutoProxy
@EnableAutoConfiguration // (exclude = EurekaClientConfigBean.class)
@EnableAutoConfiguration
@Configuration
@EnableTransactionManagement
@PropertySource(value = {"classpath:configservice.properties"})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ctrip.framework.apollo.metaservice.controller;

import com.ctrip.framework.apollo.core.ServiceNameConsts;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.metaservice.service.DiscoveryService;
import com.google.common.collect.Lists;
import java.util.List;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
* For kubernetes discovery service, there is no eureka home page, so we need to add a default one
*/
@Profile({"kubernetes"})
@RestController
public class KubernetesHomePageController {
private final DiscoveryService discoveryService;

public KubernetesHomePageController(DiscoveryService discoveryService) {
this.discoveryService = discoveryService;
}

@GetMapping("/")
public List<ServiceDTO> listAllServices() {
List<ServiceDTO> allServices = Lists.newLinkedList();
allServices
.addAll(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE));
allServices.addAll(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_ADMINSERVICE));

return allServices;
}
}
69 changes: 37 additions & 32 deletions apollo-configservice/src/main/scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,46 +116,51 @@ if [[ ! -f PATH_TO_JAR && -d current ]]; then
done
fi

if [[ -f $SERVICE_NAME".jar" ]]; then
rm -rf $SERVICE_NAME".jar"
fi
# For Docker environment, start in foreground mode
if [[ -n "$APOLLO_RUN_MODE" ]] && [[ "$APOLLO_RUN_MODE" == "Docker" ]]; then
$javaexe -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar $PATH_TO_JAR
else
if [[ -f $SERVICE_NAME".jar" ]]; then
rm -rf $SERVICE_NAME".jar"
fi

printf "$(date) ==== Starting ==== \n"
printf "$(date) ==== Starting ==== \n"

ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start
ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start

rc=$?;
rc=$?;

if [[ $rc != 0 ]];
then
echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
exit $rc;
fi
if [[ $rc != 0 ]];
then
echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
exit $rc;
fi

declare -i counter=0
declare -i max_counter=48 # 48*5=240s
declare -i total_time=0
declare -i counter=0
declare -i max_counter=48 # 48*5=240s
declare -i total_time=0

printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
sleep 5
printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
sleep 5

checkPidAlive
done
checkPidAlive
done

total_time=counter*5
total_time=counter*5

if [[ (( counter -ge max_counter )) ]];
then
printf "\n$(date) Server failed to start in $total_time seconds!\n"
exit 1;
fi
if [[ (( counter -ge max_counter )) ]];
then
printf "\n$(date) Server failed to start in $total_time seconds!\n"
exit 1;
fi

printf "\n$(date) Server started in $total_time seconds!\n"
printf "\n$(date) Server started in $total_time seconds!\n"

exit 0;
exit 0;
fi
Loading

0 comments on commit 885e461

Please sign in to comment.