feat: add build docker image

This commit is contained in:
luochao 2024-05-01 00:31:49 +08:00
parent 26fc5c0781
commit 8e23ec740b
3 changed files with 71 additions and 0 deletions

38
.github/workflows/docker-image-ci.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: Docker Image CI
on:
push:
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: get version
id: vars
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\/v/}
- uses: actions/checkout@v4
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: login ghrc hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: build and push
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/douyin:${{ steps.vars.outputs.version }}
ghcr.io/${{ github.repository_owner }}/douyin:latest

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
# syntax = docker/dockerfile:experimental
FROM --platform=${BUILDPLATFORM:-linux/amd64,linux/arm64} node:20-buster AS builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /src
COPY ./ ./
# RUN两次方便观察install和build, 也可以用pnpm cache and locked
RUN pnpm install
RUN npm run build
FROM --platform=${BUILDPLATFORM:-linux/amd64,linux/arm64} ghcr.io/rookie-luochao/nginx-runner:latest
COPY --from=builder /src/dist /app

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
PKG = $(shell cat package.json | grep 'name' | sed -e 's/ "name": "//g' -e 's/",//g')
VERSION = $(shell cat package.json | grep 'version' | sed -e 's/ "version": "//g' -e 's/",//g')
# 本地测试构建docker镜像建议删掉node_modulesnode_modules存在有时会导致报错
docker-build:
docker build . -t $(PKG):$(VERSION)
# 请先创建自己的 buildx driver 实例请看https://juejin.cn/post/7296763284647542838
# 显式指定可执行 docker buildx build --platform linux/amd64,linux/arm64 . -t $(PKG):$(VERSION) --push
docker-buildx-build:
docker buildx build --platform linux/amd64 . -t $(PKG):$(VERSION) --load
docker-run:
docker run -d -p 80:80 $(PKG):$(VERSION)
docker-build-run: docker-build docker-run