Files
myk3sTest/.gitea/workflows/build.yml

73 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Push and Deploy Image
on:
push:
branches:
- main
workflow_dispatch: #手动构建
env:
PATH: /opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REGISTRY: registry.cn-chengdu.aliyuncs.com
IMAGE_NAME: bamanker/myk3stest
CONTAINER_NAME: myk3stest
jobs:
# 构建 Job
build:
runs-on: host
outputs: # 声明作业的输出变量,方便在其他 Job 引用
datetime: ${{ steps.datetime.outputs.datetime }}
steps:
# 下载仓库源码依赖java环境因此构建服务器本地需要下载安装java并设置环境变量
- name: Checkout repository code
uses: https://gitee.com/bamanker/checkout@v5
- name: Set up Java
uses: https://gitee.com/bamanker/setup-java@v5
with:
java-version: '25.0.1'
distribution: 'openjdk'
cache: 'maven'
- name: Build with Maven
run: mvn package -DskipTests -Pprod
# 登录镜像仓库,方便后续上传镜像
- name: Login to Docker Registry
uses: https://gitee.com/bamanker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
# 这里也可以通过 secrets 传入,后面再介绍
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 获取时间戳,用于设置镜像 TAG 版本
- name: Get datetime
id: datetime
run: |
echo "datetime=$(date '+%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT
# 构建并上传镜像
- name: Build and push Docker image
uses: https://gitee.com/bamanker/build-push-action@v6
with:
context: .
platforms: linux/amd64
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.datetime.outputs.datetime }}
- name: k8s Check and Apply New Deployment
uses: https://gitee.com/bamanker/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: apply -f http://${{ secrets.DEVOPS_GITEA_TOKEN }}@/bamanker/myk3sTest/src/branch/master/.deploy/deployment.yml
- name: k8s Update Deployment
uses: https://gitee.com/bamanker/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout restart deployment ${{ env.CONTAINER_NAME }}-${{ gitea.ref_name }}