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