package com.bolingcavalry.jdk8mavenspringboot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class Hello {
@RequestMapping(value = “/hello”, method = RequestMethod.GET)
public String hello() {
return "Hello world, " + new Date();
}
}
server.port=8082
FROM maven:3.6.3-openjdk-8 as builder
WORKDIR /home/app
COPY . /home/app/
RUN cd function && mvn clean package -U -DskipTests --settings ./m2/settings.xml
RUN cp /home/app/function/target/*.jar ./application.jar
RUN java -Djarmode=layertools -jar application.jar extract
FROM openfaas/of-watchdog:0.7.6 as watchdog
FROM openjdk:8-jre-slim as ship
RUN addgroup --system app \
&& adduser --system --ingroup app app
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
WORKDIR /home/app
COPY --from=builder /home/app/dependencies/ ./
COPY --from=builder /home/app/spring-boot-loader/ ./
COPY --from=builder /home/app/snapshot-dependencies/ ./
COPY --from=builder /home/app/application/ ./
user app
WORKDIR /home/app/
ENV upstream_url=“http://127.0.0.1:8082”
ENV mode=“http”
ENV fprocess=“java org.springframework.boot.loader.JarLauncher”
EXPOSE 8080
HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1
CMD [“fwatchdog”]
新建一个文件夹,名为simplespringboot;
simplespringboot目录下新建文件template.yml,内容如下:
language: simplespringboot
welcome_message: |
You have created a function using the java8 and maven and springboot template
将前面的Dockerfile文件复制到simplespringboot目录下;
前面咱们创建的springboot工程,最外层的文件夹名为jdk8mavenspringboot,请将此文件夹改名为function,然后将整个文件夹都复制到simplespringboot目录下;
此刻的simplespringboot目录下应该是这些内容:
[root@hedy 003]# tree simplespringboot
simplespringboot
├── Dockerfile
├── function
│ ├── HELP.md
│ ├── j
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
dk8mavenspringboot.iml
│ ├── m2
│ │ └── settings.xml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── bolingcavalry
│ │ │ └── jdk8mavenspringboot
│ │ │ ├── controller
│ │ │ │ └── Hello.java
│ │ │ └── Jdk8mavenspringbootApplication.java
│ │ └── resources
│ │ ├── application.properties
│ │ ├── static
│ │ └── templates
│ └── test
│ └── java
│ └── com
│ └── bolingcavalry
│ └── jdk8mavenspringboot
│ └── Jdk8mavenspringbootApplicationTests.java
└── template.yml
17 directories, 12 files
faas template pull https://github.com/zq2599/openfaas-templates
[root@hedy 07]# faas template pull https://github.com/zq2599/openfaas-templates
Fetch templates from repository: https://github.com/zq2599/openfaas-templates at
2021/03/07 20:30:24 Attempting to expand templates from https://github.com/zq2599/openfaas-templates
2021/03/07 20:30:29 Fetched 4 template(s) : [dockerfile java11extend simplejava8 simplespringboot] from https://github.com/zq2599/openfaas-templates
[root@hedy 07]# faas new --list
Languages available as templates:
dockerfile
java11extend
simplejava8
simplespringboot
[root@hedy 07]# tree template/simplespringboot/
template/simplespringboot/
├── Dockerfile
├── function
│ ├── m2
│ │ └── settings.xml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── bolingcavalry
│ │ │ └── jdk8mavenspringboot
│ │ │ ├── controller
│ │ │ │ └── Hello.java
│ │ │ └── Jdk8mavenspringbootApplication.java
│ │ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── bolingcavalry
│ └── jdk8mavenspringboot
│ └── Jdk8mavenspringbootApplicationTests.java
└── template.yml
15 directories, 10 files
faas-cli new faas-simplespringbootdemo --lang simplespringboot -p bolingcavalry
[root@hedy 07]# faas-cli new faas-simplespringbootdemo --lang simplespringboot -p bolingcavalry
Folder: faas-simplespringbootdemo created.
/ _ \ _ __ ___ _ __ | __| _ __ _/ ___|
| | | | '_ \ / _ \ '_ | |_ / |/ _
__ \
| || | |) | / | | | | (| | (| |) |
_/| ./ ___|| ||| _,|_,|___/
|_|
Function created in folder: faas-simplespringbootdemo
Stack file written: faas-simplespringbootdemo.yml
Notes:
You have created a function using the java8 and maven and springboot template
[root@hedy 07]# tree faas-simplespringbootdemo
faas-simplespringbootdemo
├── m2
│ └── settings.xml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── bolingcavalry
│ │ └── jdk8mavenspringboot
│ │ ├── controller
│ │ │ └── Hello.java
│ │ └── Jdk8mavenspringbootApplication.java
│ └── resources
│ └── application.properties
└── test
└── java
└── com
└── bolingcavalry
└── jdk8mavenspringboot
└── Jdk8mavenspringbootApplicationTests.java
14 directories, 8 files