本篇将介绍如何通过 Github 的 Action 自动化脚本制作 whistle 的 docker 镜像并发布到 ghcr.io 上。
https://github.com/codezm/whistle
Dockerfile
1 2 3 4 5
| FROM node:lts-alpine3.18
RUN npm install -g whistle
CMD ["w2 run"]
|
Actions
任何 Git 的 push 动作将触发脚本的执行。本脚本将构建 linux/amd64 平台的 docker 镜像,交叉编译多平台可参见:https://github.com/codezm/whistle/blob/master/.github/workflows/docker.yml
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
| name: Docker Image CI
on: push
env: GHCR_IMAGE_NAME: ${{ github.repository }} GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} GHCR_USERNAME: ${{ github.actor }}
jobs: docker_build: runs-on: ubuntu-latest permissions: contents: read packages: write attestations: write steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0
- name: Login to GHCR uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ env.GHCR_USERNAME }} password: ${{ env.GHCR_TOKEN }}
- name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: | ghcr.io/${{ env.GHCR_IMAGE_NAME }} tags: | type=ref,event=tag type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} type=pep440,pattern={{raw}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Build and push uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}
|