简化工作流,合并相关任务,移除中间产物上传步骤
This commit is contained in:
parent
e54ed965de
commit
90c3c3cee7
@ -14,7 +14,7 @@ defaults:
|
||||
shell: 'bash -Eeo pipefail -x {0}'
|
||||
|
||||
jobs:
|
||||
build-nginx:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
@ -104,40 +104,12 @@ jobs:
|
||||
echo "停止 NGINX..."
|
||||
sudo /usr/local/nginx/sbin/nginx -s quit
|
||||
|
||||
- name: 准备构建产物
|
||||
- name: 准备构建上下文
|
||||
run: |
|
||||
echo "复制 nginx 文件到构建上下文..."
|
||||
sudo cp -r /usr/local/nginx ./nginx-install
|
||||
sudo chown -R $(whoami):$(whoami) ./nginx-install
|
||||
|
||||
# 打包构建产物供后续步骤使用
|
||||
tar -czf nginx-install.tar.gz ./nginx-install
|
||||
|
||||
- name: 上传构建产物
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: nginx-install
|
||||
path: nginx-install.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
build-docker-image:
|
||||
needs: build-nginx
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 下载构建产物
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: nginx-install
|
||||
|
||||
- name: 准备构建上下文
|
||||
run: |
|
||||
tar -xzf nginx-install.tar.gz
|
||||
ls -la
|
||||
|
||||
- name: 创建 Dockerfile
|
||||
run: |
|
||||
cat > Dockerfile << 'EOF'
|
||||
@ -182,31 +154,6 @@ jobs:
|
||||
echo "构建 Docker 镜像..."
|
||||
docker build -t nginx-local:latest .
|
||||
|
||||
- name: 保存 Docker 镜像
|
||||
run: |
|
||||
docker save nginx-local:latest > nginx-image.tar
|
||||
|
||||
- name: 上传 Docker 镜像
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: nginx-docker-image
|
||||
path: nginx-image.tar
|
||||
retention-days: 1
|
||||
|
||||
push-to-harbor:
|
||||
needs: build-docker-image
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: 下载 Docker 镜像
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: nginx-docker-image
|
||||
|
||||
- name: 加载 Docker 镜像
|
||||
run: |
|
||||
docker load < nginx-image.tar
|
||||
|
||||
- name: 登录到 Harbor
|
||||
run: |
|
||||
echo "登录到 Harbor 仓库..."
|
||||
@ -228,7 +175,7 @@ jobs:
|
||||
docker rmi ${{ secrets.HARBOR_REGISTRY }}/test/nginx:latest || true
|
||||
|
||||
deploy-to-kubernetes:
|
||||
needs: push-to-harbor
|
||||
needs: build-and-push
|
||||
runs-on: ubuntu-22.04
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user