Gitea Actions/Github Actions 构建 Quarkus 多平台 Native Docker 镜像
借助 Gitea Actions/Github Actions 实现发布版本后,自动打包 Quarkus 项目并构建成 Native Docker 镜像,推送到阿里云 Docker 仓库中借助 Gitea Actions/Github Actions 实现发布版本后,自动打包 SpringBoot 项目并构建成 Docker 镜像,推送到阿里云 Docker 仓库中,并通过企业微信机器人发送消息通知
一、准备Quarkus项目
使用 idea
新建即可,选择Gradle,java版本选择17
二、准备Dockerfile
1 2 3 4 5 6 7
| FROM seepine/alpine-glibc WORKDIR /work/ COPY ./build/*-runner /work/application RUN chmod 775 /work EXPOSE 8080 CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
|
三、准备build.yaml
新建.gitea/workflows/build.yaml
文件
需要提前配置 Docker 仓库的密码到 Secrets 中,若需要企业微信通知,也需要配置企业微信机器人的 WebHook 到 Secrets 中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
name: Build Images
on: push: tags: - v* env: DOCKER_REGISTRY: registry.cn-hangzhou.aliyuncs.com DOCKER_USERNAME: seepine jobs: build-image: runs-on: ubuntu-latest container: image: seepine/ubuntu:act volumes: - ubuntu_dockercache:/opt/dockercache steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 1
- name: Setup Graalvm uses: graalvm/setup-graalvm@v1 with: java-version: '17' version: '22.3.2' components: 'native-image' cache: 'gradle'
- name: Build Project run: | chmod a+x ./gradlew ./gradlew build -Dquarkus.package.type=native -x test --no-daemon
- name: Set up QEMU uses: docker/setup-qemu-action@v2
- name: Set up Docker BuildX uses: docker/setup-buildx-action@v2
- name: Login to DockerHub uses: docker/login-action@v2 with: registry: ${{ env.DOCKER_REGISTRY }} username: ${{ env.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get Meta run: | echo REPO_VERSION=$(echo ${{ github.ref }} | awk -F"/" '{print $3}' | awk -F"v" '{print $2}') >> $GITHUB_ENV echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_ENV
- name: Build and push uses: docker/build-push-action@v4 with: context: . file: Dockerfile platforms: | linux/amd64 linux/arm64 push: true tags: | ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:latest ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:${{ env.REPO_VERSION }} cache-from: type=local,src=/opt/dockercache/.buildx-${{ steps.meta.outputs.REPO_NAME }}-cache cache-to: type=local,dest=/opt/dockercache/.buildx-${{ steps.meta.outputs.REPO_NAME }}-cache-new,mode=max
- name: Rebuild docker cache run: | rm -rf /opt/dockercache/.buildx-${{ steps.meta.outputs.REPO_NAME }}-cache mv /opt/dockercache/.buildx-${{ steps.meta.outputs.REPO_NAME }}-cache-new /opt/dockercache/.buildx-${{ steps.meta.outputs.REPO_NAME }}-cache
- name: WeChat Work notification uses: seepine/action-wechat-work@master if: ${{ env.WECHAT_WORK_BOT_WEBHOOK != '' }} env: WECHAT_WORK_BOT_WEBHOOK: ${{ secrets.WECHAT_WORK_BOT_WEBHOOK }} with: msgtype: markdown content: "${{ steps.meta.outputs.REPO_NAME }}构建成功。\n > 镜像: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}"
|
四、发布版本
当我们发布一个 v1.0.0
版本时,将会看到 Actions 进行工作,最终执行完成后将会推送构建成功的消息到企业微信中,消息为
1 2
| springboot-demo构建成功。 镜像: registry.cn-hangzhou.aliyuncs.com/seepine/springboot-demo:1.0.0
|
五、运行
1
| docker run --rm -p 8080:8080 registry.cn-hangzhou.aliyuncs.com/seepine/quarkus-demo:1.0.0
|