From 7ea915c10a9a3b9c160ac79b8f33cedc838ca260 Mon Sep 17 00:00:00 2001 From: besscroft Date: Tue, 5 Dec 2023 23:33:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(ci):=E6=96=B0=E5=A2=9E=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E9=83=A8=E7=BD=B2=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-dev.yaml | 46 ++++++++++ .github/workflows/build-main.yaml | 46 ++++++++++ .github/workflows/build-release.yaml | 46 ++++++++++ Dockerfile | 13 +++ README.md | 121 +++++++++++++++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 .github/workflows/build-dev.yaml create mode 100644 .github/workflows/build-main.yaml create mode 100644 .github/workflows/build-release.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build-dev.yaml b/.github/workflows/build-dev.yaml new file mode 100644 index 0000000..3b8a838 --- /dev/null +++ b/.github/workflows/build-dev.yaml @@ -0,0 +1,46 @@ +name: Dev Docker Multi-arch Image CI & CD + +on: + push: + branches: + - dev + +jobs: + build: + name: Running Compile Nuxt3 Multi-arch Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout kamera + uses: actions/checkout@v4 + - name: Get Version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Install pnpm + run: npm install -g pnpm + - name: Install dependencies + run: pnpm i + - name: Build Nuxt 3 + run: pnpm run build + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: set_up_buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push dev + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/kamera:dev diff --git a/.github/workflows/build-main.yaml b/.github/workflows/build-main.yaml new file mode 100644 index 0000000..612a52e --- /dev/null +++ b/.github/workflows/build-main.yaml @@ -0,0 +1,46 @@ +name: Main Docker Multi-arch Image CI & CD + +on: + push: + branches: + - main + +jobs: + build: + name: Running Compile Nuxt3 Multi-arch Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout kamera + uses: actions/checkout@v4 + - name: Get Version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Install pnpm + run: npm install -g pnpm + - name: Install dependencies + run: pnpm i + - name: Build Nuxt 3 + run: pnpm run build + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: set_up_buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push latest + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/kamera:latest diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml new file mode 100644 index 0000000..a92849a --- /dev/null +++ b/.github/workflows/build-release.yaml @@ -0,0 +1,46 @@ +name: Release Docker Multi-arch Image CI & CD + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Running Compile Nuxt3 Release Multi-arch Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout kamera + uses: actions/checkout@v4 + - name: Get Version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Install pnpm + run: npm install -g pnpm + - name: Install dependencies + run: pnpm i + - name: Build Nuxt 3 + run: pnpm run build + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: set_up_buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push version + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/kamera:${{ steps.get_version.outputs.VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f70b41c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:18-slim AS base + +ENV TZ="Asia/Shanghai" + +WORKDIR /app + +COPY .output /app/.output + +EXPOSE 3000 + +CMD ["node", "/app/.output/server/index.mjs"] + +MAINTAINER besscroft diff --git a/README.md b/README.md index 2d57663..02a72e8 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,127 @@ export default defineAppConfig({ > 虽然您可以修改源码再部署,但我们希望您能保留 Made with 和 GitHub 仓库地址。 +如果你要修改音乐列表,请在 `assets/server/music.json` 下更改,可以换成你自己的。 + +### 容器部署 + +我把容器部署往后放,是不希望前面的内容被跳过,这样你在构建/部署时才能得心应手! + +#### 直接部署 + +如果你想用我的镜像(由 GitHub Actions 构建),就意味着你的某些配置与我相同,比如网站的几个目录。 +但实际上你肯定得改一下网站标题,配置子页面啊之类的,改一下音乐播放器里面的歌之类的。 +至于为啥我没有做成动态从数据库获取,主要还是觉得没太大必要(懒~ + +所以我的镜像只适合你快速体验预览之类的,还是建议你自己构建,反正也很方便,或者你直接部署到 Vercel 之类的平台。 +如果你要运行我的镜像,你只需要执行下面的命令即可部署: + +```shell +docker run -d --name kamera \ + -p 3000:3000 \ + -e Postgre_HOST="db.supabase.co" \ + -e Postgre_PORT="5432" \ + -e Postgre_DATABASE="postgres" \ + -e Postgre_USERNAME="postgres" \ + -e Postgre_PASSWORD="postgres" \ + -e AUTH_KEY="kamera" \ + -e AccessKey_ID="postgres" \ + -e AccessKey_Secret="postgres" \ + -e Region="postgres" \ + -e Endpoint="postgres.aliyuncs.com" \ + -e Bucket="postgres" \ + -e STORAGE_FOLDER="kamera" \ + -e CDN_URL="kamera-s3-cdn.heming.dev" \ + -e STORAGE_MODEL="s3" \ + -e KAMERA_USERNAME="admin" \ + -e KAMERA_PASSWORD="2a2a3d2b5dcef92937839896bcf07dc62605ebe2ac428f57ea061c734d950d075667654a5e130a9fee5b85512a98eac8138100f32a40953b8678243dbfc97297" \ + besscroft/kamera:latest +``` + +> 看到这里您应该明白,环境变量当然要换成自己的! + +#### 自己构建镜像 + +无需多说,直接 fork 本项目,然后更改任意文件并 `commit` 后,会自动触发 GitHub Actions 构建。 +当然在那之前,你需要先在你 fork 的仓库创建 2 个机密,具体看[为存储库创建机密](https://docs.github.com/zh/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) + +> `DOCKERHUB_USERNAME` 和 `DOCKERHUB_TOKEN` 这两个,这样才能在构建后,上传到你自己的 docker 仓库去。 + +在构建好镜像之后,你可以用上面的命令执行,如果你要 Docker Compose 执行: + +```shell +version: '3' +services: + kamera: + image: besscroft/kamera:latest + container_name: kamera + ports: + - 3000:3000 + environment: + - Postgre_HOST="db.supabase.co" + - Postgre_PORT=5432 + - Postgre_DATABASE="postgres" + - Postgre_USERNAME="postgres" + - Postgre_PASSWORD="postgres" + - AUTH_KEY="kamera" + - AccessKey_ID="postgres" + - AccessKey_Secret="postgres" + - Region="postgres" + - Endpoint="postgres.aliyuncs.com" + - Bucket="postgres" + - STORAGE_FOLDER="kamera" + - CDN_URL="kamera-s3-cdn.heming.dev" + - STORAGE_MODEL="s3" + - KAMERA_USERNAME="admin" + - KAMERA_PASSWORD="2a2a3d2b5dcef92937839896bcf07dc62605ebe2ac428f57ea061c734d950d075667654a5e130a9fee5b85512a98eac8138100f32a40953b8678243dbfc97297" +``` + +> 一样的,参考上面的环境变量表格,配置你自己的环境变量。 + +#### 构建镜像 Q&A + +Q:我 fork 仓库后,网站设置也改了自己的之后,构建的镜像是被人 pull 有风险吗? + +A:原则上没有,但如果你自己要往文件里面填写机密信息,那是你自己的问题! +别人并不知道你的环境变量的值,除非你自己泄露! + +Q:用你这玩意怎么这么麻烦?人家的都能放数据库里面,访问时动态获取。 + +A:没错,我是懒狗。但是这部分内容我觉得真没太大必要每次还从数据库查(即使做缓存又如何呢?)。 +基于 SSR 的特性大部分配置内容,是在编译期处理的,比如咱们配置的那些自定义页面。 + +#### 自行编译并部署 + +这种方式适合那些想自己打包直接放在 Node 上跑的朋友。 + +```shell +git clone https://github.com/besscroft/kamera.git + +pnpm i + +pnpm run build +``` + +构建完成后,你会看到一个 `.output` 文件夹,你可以使用如下命令运行: + +```shell +node /app/.output/server/index.mjs +``` + +> 如果你选择这种部署方式,我相信你是会使用 Node 的。 + +#### 宝塔面板 + +对于使用宝塔面板之类的用户,包括使用 Nginx 来提供访问服务的用户,记得配置反向代理: + +```shell +location ^~ // { + proxy_pass http://localhost:3000; +} +``` + +> 端口和路径之类的,就看你自己部署时,设置的什么了。 + ### 在线开发 你可以使用 Gitpod 进行在线开发: From a60f505e611e912b07848b352de780b8bae38c25 Mon Sep 17 00:00:00 2001 From: besscroft Date: Tue, 5 Dec 2023 23:39:47 +0800 Subject: [PATCH 2/2] doc(readme):update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02a72e8..7ead2b5 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ docker run -d --name kamera \ > `DOCKERHUB_USERNAME` 和 `DOCKERHUB_TOKEN` 这两个,这样才能在构建后,上传到你自己的 docker 仓库去。 -在构建好镜像之后,你可以用上面的命令执行,如果你要 Docker Compose 执行: +在构建好镜像之后,你可以用上面的命令执行(记得镜像换成你自己构建的哈),如果你要 Docker Compose 执行: ```shell version: '3'