This commit is contained in:
40
.github/workflows/deploy.yml
vendored
40
.github/workflows/deploy.yml
vendored
@@ -36,6 +36,11 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Pull base Docker image
|
||||
run: |
|
||||
docker pull openjdk:17-jdk-slim
|
||||
docker images
|
||||
|
||||
- name: Login to Docker Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v2
|
||||
@@ -54,26 +59,47 @@ jobs:
|
||||
type=sha,prefix={{branch}}-
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push Docker image with Jib
|
||||
- name: Build Docker image with Jib to local Docker daemon
|
||||
run: |
|
||||
mvn jib:build \
|
||||
mvn jib:dockerBuild \
|
||||
-Djib.to.image=light-delivery-app:${{ github.sha }} \
|
||||
-Djib.allowInsecureRegistries=true \
|
||||
-Djib.httpTimeout=60000 \
|
||||
-Djib.sendCredentialsOverHttp=false
|
||||
-Djib.sendCredentialsOverHttp=false \
|
||||
-Djib.pullParentImage=false \
|
||||
-Djib.containerizingMode=packaged
|
||||
env:
|
||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Deploy to server via SSH
|
||||
- name: Export Docker image as tar file
|
||||
run: |
|
||||
mvn jib:buildTar \
|
||||
-Djib.to.image=light-delivery-app:${{ github.sha }} \
|
||||
-Djib.allowInsecureRegistries=true \
|
||||
-Djib.httpTimeout=60000 \
|
||||
-Djib.sendCredentialsOverHttp=false \
|
||||
-Djib.pullParentImage=false
|
||||
ls -la target/jib-image.tar
|
||||
|
||||
- name: Deploy to server via SCP and SSH
|
||||
uses: appleboy/scp-action@v0.1.4
|
||||
with:
|
||||
host: 115.190.121.151
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
source: "target/jib-image.tar"
|
||||
target: "/tmp/"
|
||||
|
||||
- name: Load and run Docker image on server
|
||||
uses: appleboy/ssh-action@v0.1.5
|
||||
with:
|
||||
host: 115.190.121.151
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
script: |
|
||||
# 拉取新镜像
|
||||
docker pull light-delivery-app:${{ github.sha }}
|
||||
# 加载Docker镜像
|
||||
docker load -i /tmp/jib-image.tar
|
||||
# 停止并删除旧容器
|
||||
docker stop light-delivery-app || true
|
||||
docker rm light-delivery-app || true
|
||||
@@ -88,5 +114,7 @@ jobs:
|
||||
-e SPRING_DATASOURCE_PASSWORD=Hu@ng1998! \
|
||||
-v /etc/ssl/certs:/etc/ssl/certs \
|
||||
light-delivery-app:${{ github.sha }}
|
||||
# 清理tar文件
|
||||
rm /tmp/jib-image.tar
|
||||
# 清理旧镜像
|
||||
docker image prune -f
|
7
pom.xml
7
pom.xml
@@ -171,6 +171,9 @@
|
||||
<configuration>
|
||||
<from>
|
||||
<image>openjdk:17-jdk-slim</image>
|
||||
<insecureRegistries>
|
||||
<insecureRegistry>localhost:5000</insecureRegistry>
|
||||
</insecureRegistries>
|
||||
</from>
|
||||
<to>
|
||||
<image>light-delivery-app</image>
|
||||
@@ -197,10 +200,14 @@
|
||||
<!-- CI/CD环境优化配置 -->
|
||||
<httpTimeout>60000</httpTimeout>
|
||||
<retries>3</retries>
|
||||
<!-- 使用本地已有的基础镜像 -->
|
||||
<pullParentImage>false</pullParentImage>
|
||||
<!-- 镜像标签配置 -->
|
||||
<outputPaths>
|
||||
<tar>${project.build.directory}/jib-image.tar</tar>
|
||||
</outputPaths>
|
||||
<!-- 优化CI/CD构建 -->
|
||||
<containerizingMode>packaged</containerizingMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
Reference in New Issue
Block a user