Skip to content

Commit

Permalink
feat: 发布到docker
Browse files Browse the repository at this point in the history
  • Loading branch information
songxingguo committed Jan 19, 2025
1 parent 505da2e commit ac1e606
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.git
node_modules
npm-debug.log
55 changes: 55 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

name: Publish Image

on:
push: # push 到主分支自动 发布
branches: ["master"]
paths-ignore: # 忽略一些不必要的文件
- ".gitignore"
- "README.md"
- ".vscode/**"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
submodules: true
- run: |
git submodule init
git submodule update --remote
- uses: docker/login-action@v1
with:
registry: registry.cn-shanghai.aliyuncs.com # 声明镜像源
username: ${{ secrets.ALIYUN_USER }} # 当前github 用户名
password: ${{ secrets.ALIYUN_PWD }} # 需要去 https://github.com/settings/tokens 生成一个 名为 token,注意此token 需要读写 packages 等权限
- uses: actions/setup-node@v2
with:
node-version: "20.12.1"
- name: Install and Build 🔧
run: |
npm i
npm run build
- name: Show Dir
run: ls

- name: Build the Docker image
run:
| # 使用 上一步写的 Dockerfile 构建镜像并发布到私有仓库; 发布完成可以去 https://github.com/songxingguo?tab=packages 查看
docker build . --file Dockerfile --tag registry.cn-shanghai.aliyuncs.com/songxingguo/hi:latest
docker push registry.cn-shanghai.aliyuncs.com/songxingguo/hi:latest
- name: 更新服务器
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }} # 服务器ip地址 ; 需要去仓库的 settings/secrets/actions 去创建
username: ${{ secrets.SERVER_USER }} # 服务器用户名称;需要去仓库的 settings/secrets/actions 去创建
password: ${{ secrets.SERVER_PWD }} # 服务器密码;需要去仓库的 settings/secrets/actions 去创建
port: ${{ secrets.SERVER_PORT }} # 服务器端口,默认22;需要去仓库的 settings/secrets/actions 去创建
script: | # 重启更新镜像
docker login --username=${{ secrets.ALIYUN_USER }} -p ${{ secrets.ALIYUN_PWD }} registry.cn-shanghai.aliyuncs.com
docker pull registry.cn-shanghai.aliyuncs.com/songxingguo/hi:latest
cd /root/deploy && ./deploy.sh
6 changes: 3 additions & 3 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 静态博客构建
on:
push:
branches:
- master
# push:
# branches:
# - master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

FROM nginx:latest
LABEL maintainer "[email protected]"
ADD ./dist /usr/share/nginx/html
WORKDIR /usr/share/nginx/html/
RUN chown -R daemon:daemon * && chmod -R 755 *
EXPOSE 80

0 comments on commit ac1e606

Please sign in to comment.