Skip to content

Commit

Permalink
Use GitHub Actions to build docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Dec 6, 2022
1 parent cec74b3 commit 9648aad
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish Docker image

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
name:
description: 'reason'
required: false
jobs:
push_to_registries:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
justsong/wechat-server
ghcr.io/${{ github.repository }}
- name: Build and push Docker images
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ RUN npm install
RUN npm run build

FROM golang AS builder2

ENV GO111MODULE=on \
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build
COPY . .
COPY --from=builder /build/build ./web/build
RUN go mod download
RUN go build -ldflags "-s -w" -o wechat-server
RUN go build -ldflags "-s -w -extldflags '-static'" -o wechat-server

FROM scratch
FROM alpine

ENV PORT=3000
COPY --from=builder2 /build/wechat-server /
EXPOSE 3000
WORKDIR /data
ENTRYPOINT ["/wechat-server"]
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
![demo1](https://user-images.githubusercontent.com/39998050/200124147-3338a2eb-8193-4068-ae6f-276cfe16a708.png)
![demo2](https://user-images.githubusercontent.com/39998050/200124177-78636b4c-0aac-4860-a138-68f3d92477b9.png)

## 部署
### 手动部署
1.[GitHub Releases](https://github.com/songquanpeng/wechat-server/releases/latest) 下载可执行文件或者从源码编译:
```shell
git clone https://github.com/songquanpeng/wechat-server.git
go mod download
go build -ldflags "-s -w" -o wechat-server
````
2. 运行:
```shell
chmod u+x wechat-server
./wechat-server --port 3000 --log-dir ./logs
```
3. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456`

更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。

### 基于 Docker 进行部署
执行:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/wechat-server:/data justsong/wechat-server`

数据将会保存在宿主机的 `/home/ubuntu/data/wechat-server` 目录。

## 配置
1. 从 [GitHub Releases](https://github.com/songquanpeng/wechat-server/releases/latest) 下载可执行文件。
2. 系统本身开箱即用,有一些环境变量可供配置:
Expand Down
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var WeChatMenu = `{
}`

var SessionSecret = uuid.New().String()
var SQLitePath = ".wechat-server.db"
var SQLitePath = "wechat-server.db"

var OptionMap map[string]string
var OptionMapRWMutex sync.RWMutex
Expand Down

0 comments on commit 9648aad

Please sign in to comment.