Skip to content

Commit

Permalink
ci: docker镜像构建
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 4, 2024
1 parent 2bad258 commit 226e08e
Show file tree
Hide file tree
Showing 27 changed files with 333 additions and 92 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
/runtime
/bin

data.db

/frontend/node_modules
/frontend/dist
/data
60 changes: 60 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker

on:
push:
branches:
- main

env:
APP_NAME: ${{ github.event.repository.name }}
NAMESPACE: app
REGISTRY: ${{ secrets.DOCKER_REGISTRY && secrets.DOCKER_REGISTRY || 'docker.io' }}
REPOSITORY: ${{ github.repository }}

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Mkdir
run: |
mkdir -p frontend/dist
echo "" > frontend/dist/index.html
- name: Lint
uses: golangci/golangci-lint-action@v6

- name: Tests
run: |
go test $(go list ./...)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Set outputs
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Docker build and push
uses: docker/build-push-action@v5
with:
push: true
file: Dockerfile
tags: ${{ env.REPOSITORY }}:${{ steps.vars.outputs.sha_short }}
context: .
34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
push:
branches:
- !main
- !release/*
- !test/*

pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
install-mode: goinstall
args: --timeout=30m

- name: Tests
run: |
go test $(go list ./...)
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@

/runtime
/bin

data.db
/datworkflowsa
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
- nolintlint

run:
timeout: 10m
timeout: 10m

linters-settings:
stylecheck:
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ WORKDIR /app

COPY --from=build /app/bin /app/dns-kit

CMD ["/app/dns-kit"]
COPY ./configs/config.yaml.example /app/configs/config.yaml.example

COPY ./deploy/entrypoint.sh /app/entrypoint.sh

RUN chmod +x /app/entrypoint.sh && chmod +x /app/dns-kit

ENTRYPOINT ["/app/entrypoint.sh"]

CMD ["/app/dns-kit","--config","./runtime/config.yaml"]
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ build:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o bin/$(APP_NAME)_v$(APP_VERSION)$(SUFFIX) ./cmd/app

docker:
docker build -t $(APP_NAME):$(APP_VERSION) .
docker build --platform=$(GOOS)/$(GOARCH) -t $(APP_NAME):$(APP_VERSION) .

docker-push:
docker tag $(APP_NAME):$(APP_VERSION) codfrm/$(APP_NAME):$(APP_VERSION)
#docker push codfrm/$(APP_NAME):$(APP_VERSION)
docker tag $(APP_NAME):$(APP_VERSION) codfrm/$(APP_NAME):latest
#docker push codfrm/$(APP_NAME):latest
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
# DNS Kit
# DNS Kit
> 一个可以申请SSL证书部署到CDN的工具
![32c977b8bcba2d7b5b7062c589a3889c](img/README.assets/32c977b8bcba2d7b5b7062c589a3889c.png)

## 功能

- 支持管理多平台DNS记录
- 支持管理多平台CDN
- 支持自动申请SSL证书
- 支持自动部署SSL证书到CDN

## 支持平台

- 腾讯云(CDN、DNS)
- 阿里云(DNS)
- 七牛云(CDN)
- Cloudflare(DNS)
- Kubernetes(CDN)

## 部署方式

### Docker(推荐)

```
docker run -d \
-v $PWD/data:/app/runtime \
-p 5174:5174 \
--name dns-kit \
--restart unless-stopped \
codfrm/dns-kit:latest
```

### docker-compose(推荐)

```yaml
version: '3'

services:
dns-kit:
image: codfrm/dns-kit:latest
container_name: dns-kit
restart: unless-stopped
volumes:
- ./data:/app/runtime
ports:
- "5174:5174"
```

```bash
docker-compose up -d
```

### 从源代码

从源代码构建需要预先准备好以下环境:

- go 1.22+
- node 20+
- yarn

```bash
git clone https://github.com/CodFrm/dns-kit.git
cd dns-kit
make build
# 创建配置文件
cp ./configs/config.example.yaml ./configs/config.yaml
# 启动, 默认端口为5174, 版本号根据实际情况修改
./bin/dns-kit_v1.0.0
```

## 使用

访问 http://localhost:5174 默认账号密码为 `admin` `123456`

7 changes: 6 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"log"

"github.com/codfrm/cago"
Expand Down Expand Up @@ -29,8 +30,12 @@ import (
)

func main() {
var configFile string
flag.StringVar(&configFile, "config", "./configs/config.yaml", "config file")
flag.Parse()

ctx := context.Background()
cfg, err := configs.NewConfig("dns-kit")
cfg, err := configs.NewConfig("dns-kit", configs.WithConfigFile(configFile))
if err != nil {
log.Fatalf("load config err: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions configs/config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
app:
encrypt_key: G7LzxQ5mmVx3Ua5
encrypt_key: ${RANDOM_STRING}
broker:
type: event_bus
cache:
type: "memory"
db:
driver: sqlite
dsn: data.db
dsn: ./runtime/data.db
prefix: null
debug: false
env: prod
http:
address:
- :8080
- :5174
logger:
disableConsole: false
level: info
Expand Down
17 changes: 17 additions & 0 deletions deploy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# 检查是否存在./runtime/config.yaml文件
if [ ! -f ./runtime/config.yaml ]; then
echo "配置文件不存在,复制默认配置文件"
mkdir -p runtime
cp ./configs/config.yaml.example ./runtime/config.yaml
# 设置默认字符串长度
LENGTH=16
# 生成随机字符串
RANDOM_STRING=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c $LENGTH)
# 替换配置文件中的变量
sed -i "s/\${RANDOM_STRING}/${RANDOM_STRING}/g" ./runtime/config.yaml
fi

# 启动应用
exec "$@"
11 changes: 11 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

services:
dns-kit:
image: codfrm/dns-kit:1.0.0
container_name: dns-kit
restart: unless-stopped
volumes:
- ./data:/app/runtime
ports:
- "5174:5174"
1 change: 1 addition & 0 deletions frontend/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package frontend

import "embed"

//nolint:typecheck

Check failure on line 5 in frontend/embed.go

View workflow job for this annotation

GitHub Actions / docker

directive `//nolint:typecheck` is unused for linter "typecheck" (nolintlint)
//go:embed dist
var EmbedFS embed.FS
1 change: 1 addition & 0 deletions frontend/src/pages/certificate/hosting/add-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const AddForm: React.FC<{
if (props.visible) {
form.resetFields();
}
form.setFieldValue('type', type);
}, [props.visible]);

const PlaformForm = platformForm[platform];
Expand Down
Loading

0 comments on commit 226e08e

Please sign in to comment.