Creating dockerfile that creates the server image.

Also modifying .gitlab-ci file to push docker image to the registry
This commit is contained in:
Arpit Mohan 2019-11-14 12:50:37 +00:00
parent 98662714dc
commit 8fbf61502f
6 changed files with 65 additions and 65 deletions

View File

@ -1,11 +1,10 @@
.only-default: &only-default .only-default: &only-default
only: only:
- release
- master - master
- merge_requests - merge_requests
image: docker:latest image: docker:latest
services:
- redis
cache: cache:
paths: paths:
@ -26,20 +25,40 @@ stages:
maven-build: maven-build:
image: maven:3-jdk-11-slim image: maven:3-jdk-11-slim
stage: build stage: build
services:
- redis
script: script:
- mvn package -B -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE - mvn package -B -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE
artifacts: artifacts:
paths: paths:
- appsmith-server/target/*.jar - appsmith-server/target/*.jar
- appsmith-plugins/*/target/*.jar
only: only:
- release
- master - master
- merge_requests - merge_requests
docker-package: docker-package:
image: maven:3-jdk-11-slim image: docker:dind
services:
- docker:dind
stage: package stage: package
script: script:
- mvn package -DskipTests -DskipDockerBuild=false - docker build -t arpitappsmith/appsmith-server:release .
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_ACCESS_TOKEN
- docker push arpitappsmith/appsmith-server:release
only:
- release
docker-package-master:
image: docker:dind
services:
- docker:dind
stage: package
script:
- docker build -t arpitappsmith/appsmith-server:latest .
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_ACCESS_TOKEN
- docker push arpitappsmith/appsmith-server:latest
only: only:
- master - master
@ -49,4 +68,4 @@ heroku-deploy:
script: script:
- dpl --provider=heroku --app=appsmith-test --api-key=$HEROKU_API_KEY - dpl --provider=heroku --app=appsmith-test --api-key=$HEROKU_API_KEY
only: only:
- master - release

24
app/server/Dockerfile Normal file
View File

@ -0,0 +1,24 @@
#When you are building, name it appsmith-server which is how it is referenced in docker-compose.yml
FROM adoptopenjdk/openjdk11:alpine-jre
LABEL maintainer="tech@appsmith.com"
VOLUME /tmp
EXPOSE 8080
ARG JAR_FILE=./appsmith-server/target/server-1.0-SNAPSHOT.jar
ARG PLUGIN_JARS=./appsmith-plugins/*/target/*.jar
#Create the plugins directory
RUN mkdir -p /plugins
#Add the jar to the container. Always keep this at the end. This is to ensure that all the things that can be taken
#care of via the cache happens. The following statement would lead to copy because of change in hash value
COPY entrypoint.sh /entrypoint.sh
COPY ${JAR_FILE} server.jar
COPY ${PLUGIN_JARS} /plugins/
#Run the jar
ENTRYPOINT ["/bin/sh", "-c" , "/entrypoint.sh"]

View File

@ -19,5 +19,5 @@
<module>restApiPlugin</module> <module>restApiPlugin</module>
<module>mongoPlugin</module> <module>mongoPlugin</module>
</modules> </modules>
</project> </project>

View File

@ -8,10 +8,10 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<groupId>com.appsmith</groupId> <groupId>com.appsmith</groupId>
<artifactId>server</artifactId> <artifactId>server</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>server</name> <name>server</name>
<description>This is the API server for the Appsmith project</description> <description>This is the API server for the Appsmith project</description>
@ -109,10 +109,10 @@
<version>0.9.6</version> <version>0.9.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.flapdoodle.embed</groupId> <groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId> <artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
@ -136,12 +136,12 @@
<artifactId>interfaces</artifactId> <artifactId>interfaces</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- Plugin dependencies --> <!-- Plugin dependencies -->
<dependency> <dependency>
<groupId>org.pf4j</groupId> <groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId> <artifactId>pf4j-spring</artifactId>
<version>0.5.0</version> <version>0.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

2
app/server/entrypoint.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
java -Djava.security.egd="file:/dev/./urandom" -jar server.jar

View File

@ -39,51 +39,6 @@
</resource> </resource>
</resources> </resources>
<plugins>
<!--
This plugin optimizes the docker container for updates by making the incremental
layers smaller. Refer: https://phauer.com/2019/no-fat-jar-in-docker-image/
-->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.6.1</version>
<configuration>
<from>
<image>adoptopenjdk/openjdk11:alpine-jre</image>
</from>
<to>
<!-- Currently this image is created under Arpit's username. This is because of pricing
structure of Docker hub. Will move it to Appsmith's org account once that is resolved.
-->
<image>docker.io/arpitappsmith/appsmith-server</image>
<!-- Please define the Docker Hub credentials as environment variables.
In Gitlab, this will be defined under VARIABLES section of CI/CD Settings
-->
<auth>
<username>${env.DOCKER_HUB_USERNAME}</username>
<password>${env.DOCKER_HUB_ACCESS_TOKEN}</password>
</auth>
</to>
<container>
<jvmFlags>
<jvmFlag>-server</jvmFlag>
</jvmFlags>
</container>
<skip>${skipDockerBuild}</skip>
</configuration>
<executions>
<execution>
<id>build-and-push-docker-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> </build>