1.新建流水线,选中部署到阿里云ECS
2.配置流水线源
3.java构建上传,其他都可以默认,打包路径填写jar包路径.(切记不要填写多个打包路径,否则后面会解压到别的目前,暂未解决)
4.主机部署,部署脚本是解压和执行脚本
脚本说明
deploy.sh、compose.yaml、Dockerfile这三个脚本要提前放到服务器对应的目录
bash
image_name=ry-admin
id=$(docker ps -a | grep ${image_name} | awk '{print $1}')
if [ -n "$id" ]; then
echo "Removing container with ID: $id"
docker rm -f $id
else
echo "No container found with name '${image_name}'."
fi
id=$(docker images | grep ${image_name} | awk '{print $3}')
if [ -n "$id" ]; then
echo "Removing image with ID: $id"
docker rmi -f $id
else
echo "No image found with name '${image_name}'."
fi
docker compose -f /home/admin/ruoyi/compose.yaml up -d
echo "${image_name}部署成功!"
compose.yaml
bash
name: java-app
services:
ry-admin:
build: .
restart: always
container_name: ry-admin
ports:
- '8080:8080'
networks:
default:
external:
name: devsoft_default
Dockerfile
bash
FROM openjdk:8-jre-alpine
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ENV APP_PATH=/apps
WORKDIR $APP_PATH
# 将当前目录下的jar包复制到docker容器的/目录下
ADD *.jar $APP_PATH/app.jar
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom"
ENV PARAMS="--spring.profiles.active=prod"
EXPOSE 8080
# 指定docker容器启动时运行jar包
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $APP_PATH/app.jar $PARAMS" ]
本来这三个脚本是放在springboot项目中的,打算和jar包一起作为构建物上传,但是填写多个打包路径后在服务器上解压时路径没解决,只好提前放在服务器上