Skip to content

Commit f6fa4c3

Browse files
奇淼(piexlmaxtesuntasktscuitewyh
authored
Bug fix test (#1061)
* fix 腾讯云COS上传配置无效 * Create docker-cicd.yaml * 修复InitDataFailed 打印bug Co-authored-by: tesun <[email protected]> Co-authored-by: task <[email protected]> Co-authored-by: task <[email protected]> Co-authored-by: tscuite <[email protected]> Co-authored-by: tscuite <[email protected]> Co-authored-by: wyh <[email protected]>
1 parent 64a5251 commit f6fa4c3

File tree

10 files changed

+250
-80
lines changed

10 files changed

+250
-80
lines changed

.github/workflows/docker-cicd.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Docker-CICD
2+
on:
3+
push:
4+
branches: [main]
5+
workflow_dispatch:
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out branch
12+
uses: actions/checkout@v2
13+
- name: Login to Aliyun Registry
14+
uses: docker/login-action@v1
15+
with:
16+
registry: ${{ secrets.ALIYUN_REGISTRY }}
17+
username: ${{ secrets.ALIYUN_DOCKERHUB_USER }}
18+
password: ${{ secrets.ALIYUN_DOCKERHUB_PASSWORD }}
19+
- name: Sed Config
20+
shell: bash
21+
run: |
22+
sed -i 's#./entrypoint.sh"#./entrypoint.sh","actions"#g' Dockerfile
23+
sed -i "s#COPY build/ /usr/share/nginx/html/#COPY . /opt/gva#g" Dockerfile
24+
sed -i 16c"\ && cd /opt/gva/server/ && go mod tidy && cd /opt/gva/web/ && yarn" Dockerfile
25+
sed -i "s#open: true#open: false#g" web/vite.config.js
26+
make images TAGS_OPT="latest"
27+
docker push registry.cn-hangzhou.aliyuncs.com/gva/web:latest
28+
docker push registry.cn-hangzhou.aliyuncs.com/gva/server:latest
29+
docker push registry.cn-hangzhou.aliyuncs.com/gva/all:latest

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM centos:7
2+
WORKDIR /opt
3+
ENV LANG=en_US.utf8
4+
COPY entrypoint.sh .
5+
COPY build/ /usr/share/nginx/html/
6+
COPY server/config.yaml /usr/share/nginx/html/config.yaml
7+
COPY web/.docker-compose/nginx/conf.d/nginx.conf /etc/nginx/conf.d/nginx.conf
8+
RUN set -ex \
9+
&& echo "LANG=en_US.utf8" > /etc/locale.conf \
10+
&& echo "net.core.somaxconn = 1024" >> /etc/sysctl.conf \
11+
&& echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf \
12+
&& yum -y install yum -y install *epel* \
13+
&& yum -y localinstall http://mirrors.ustc.edu.cn/mysql-repo/mysql57-community-release-el7.rpm \
14+
&& yum -y install mysql-community-server git redis nginx go npm --nogpgcheck && chmod +x ./entrypoint.sh \
15+
&& npm install -g yarn && go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
16+
&& echo "start" > /dev/null
17+
EXPOSE 80
18+
ENTRYPOINT ["./entrypoint.sh"]

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
SHELL = /bin/bash
2+
3+
CONFIG_FILE = config.yaml
4+
PROJECT_NAME = github.com/flipped-aurora/gin-vue-admin/server
5+
#SCRIPT_DIR = $(shell pwd)/etc/script
6+
BUILD_IMAGE_SERVER = golang:1.16
7+
BUILD_IMAGE_WEB = node:16
8+
IMAGE_NAME = gva
9+
REPOSITORY = registry.cn-hangzhou.aliyuncs.com/${IMAGE_NAME}
10+
11+
ifeq ($(TAGS_OPT),)
12+
TAGS_OPT = 2.5.0b
13+
else
14+
endif
15+
16+
#容器环境前后端共同打包
17+
build: build-web build-server
18+
docker run --name build-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-local
19+
20+
#容器环境打包前端
21+
build-web:
22+
docker run --name build-web-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_WEB} make build-web-local
23+
24+
#容器环境打包后端
25+
build-server:
26+
docker run --name build-server-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-server-local
27+
28+
#构建web镜像
29+
build-image-web:
30+
@cd web/ && docker build -t ${REPOSITORY}/web:${TAGS_OPT} .
31+
32+
#构建server镜像
33+
build-image-server:
34+
@cd server/ && docker build -t ${REPOSITORY}/server:${TAGS_OPT} .
35+
36+
#本地环境打包前后端
37+
build-local:
38+
if [ -d "build" ];then rm -rf build; else echo "OK!"; fi \
39+
&& if [ -f "/.dockerenv" ];then echo "OK!"; else make build-web-local && make build-server-local; fi \
40+
&& mkdir build && cp -r web/dist build/ && cp server/server build/ && cp -r server/resource build/resource
41+
42+
#本地环境打包前端
43+
build-web-local:
44+
@cd web/ && if [ -d "dist" ];then rm -rf dist; else echo "OK!"; fi \
45+
&& yarn config set registry http://mirrors.cloud.tencent.com/npm/ \
46+
&& yarn install && yarn build
47+
48+
#本地环境打包后端
49+
build-server-local:
50+
@cd server/ && if [ -f "server" ];then rm -rf server; else echo "OK!"; fi \
51+
&& go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
52+
&& go env -w CGO_ENABLED=0 && go env && go mod tidy \
53+
&& go build -ldflags "-B 0x$(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -X main.Version=${TAGS_OPT}" -v
54+
55+
#打包前后端二合一镜像
56+
image: build
57+
docker build -t ${REPOSITORY}/all-one:${TAGS_OPT} .
58+
59+
#尝鲜版
60+
images: build build-image-web build-image-server
61+
docker build -t ${REPOSITORY}/all:${TAGS_OPT} .

entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
if [ ! -d "/var/lib/mysql/gva" ]; then
3+
mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql
4+
mysqld --daemonize --user=mysql
5+
sleep 5s
6+
mysql -uroot -e "create database gva default charset 'utf8' collate 'utf8_bin'; grant all on gva.* to 'root'@'127.0.0.1' identified by '123456'; flush privileges;"
7+
else
8+
mysqld --daemonize --user=mysql
9+
fi
10+
redis-server &
11+
if [ "$1" = "actions" ]; then
12+
cd /opt/gva/server && go run main.go &
13+
cd /opt/gva/web/ && yarn serve &
14+
else
15+
/usr/sbin/nginx &
16+
cd /usr/share/nginx/html/ && ./server &
17+
fi
18+
echo "gva ALL start!!!"
19+
tail -f /dev/null

server/service/system/sys_initdb_mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (h MysqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
8181
continue
8282
}
8383
if n, err := init.InitializeData(next); err != nil {
84-
color.Info.Printf(InitDataFailed, Mysql, err)
84+
color.Info.Printf(InitDataFailed, Mysql, init.InitializerName(), err)
8585
return err
8686
} else {
8787
next = n

server/service/system/sys_initdb_pgsql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (h PgsqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
8080
continue
8181
}
8282
if n, err := inits[i].InitializeData(next); err != nil {
83-
color.Info.Printf(InitDataFailed, Pgsql, err)
83+
color.Info.Printf(InitDataFailed, Pgsql, inits[i].InitializerName(), err)
8484
return err
8585
} else {
8686
next = n
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
#charset koi8-r;
6+
#access_log logs/host.access.log main;
7+
8+
location / {
9+
root /usr/share/nginx/html/dist;
10+
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
11+
try_files $uri $uri/ /index.html;
12+
}
13+
14+
location /api {
15+
proxy_set_header Host $http_host;
16+
proxy_set_header X-Real-IP $remote_addr;
17+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18+
proxy_set_header X-Forwarded-Proto $scheme;
19+
rewrite ^/api/(.*)$ /$1 break; #重写
20+
proxy_pass http://127.0.0.1:8888; # 设置代理服务器的协议和地址
21+
}
22+
location /form-generator {
23+
proxy_set_header Host $http_host;
24+
proxy_set_header X-Real-IP $remote_addr;
25+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26+
proxy_set_header X-Forwarded-Proto $scheme;
27+
proxy_pass http://127.0.0.1:8888;
28+
}
29+
location /api/swagger/index.html {
30+
proxy_pass http://127.0.0.1:8888/swagger/index.html;
31+
}
32+
}

web/src/components/chooseImg/index.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
22
<el-drawer v-model="drawer" title="媒体库" size="650px">
3+
<warning-bar
4+
title="点击“文件名/备注”可以编辑文件名或者备注内容。"
5+
/>
36
<div class="gva-btn-list">
47
<upload-common
58
v-model:imageCommon="imageCommon"
@@ -61,6 +64,7 @@ import { getFileList, editFileName } from '@/api/fileUploadAndDownload'
6164
import UploadImage from '@/components/upload/image.vue'
6265
import UploadCommon from '@/components/upload/common.vue'
6366
import { ElMessage, ElMessageBox } from 'element-plus'
67+
import warningBar from '@/components/warningBar/warningBar.vue'
6468
6569
const imageUrl = ref('')
6670
const imageCommon = ref('')
@@ -69,7 +73,6 @@ const search = ref({})
6973
const page = ref(1)
7074
const total = ref(0)
7175
const pageSize = ref(20)
72-
const keyword = ref('')
7376
7477
// 分页
7578
const handleSizeChange = (val) => {
@@ -128,7 +131,7 @@ const editFileNameFunc = async(row) => {
128131
cancelButtonText: '取消',
129132
inputPattern: /\S/,
130133
inputErrorMessage: '不能为空',
131-
inputValue: row.name
134+
inputValue: row.name
132135
}).then(async({ value }) => {
133136
row.name = value
134137
// console.log(row)

web/src/view/example/upload/upload.vue

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<template>
22
<div v-loading.fullscreen.lock="fullscreenLoading">
33
<div class="gva-table-box">
4+
<warning-bar
5+
title="点击“文件名/备注”可以编辑文件名或者备注内容。"
6+
/>
47
<div class="gva-btn-list">
58
<upload-common
6-
v-model:imageCommon="imageCommon"
7-
class="upload-btn"
8-
@on-success="getTableData"
9+
v-model:imageCommon="imageCommon"
10+
class="upload-btn"
11+
@on-success="getTableData"
912
/>
1013
<upload-image
11-
v-model:imageUrl="imageUrl"
12-
:file-size="512"
13-
:max-w-h="1080"
14-
class="upload-btn"
15-
@on-success="getTableData"
14+
v-model:imageUrl="imageUrl"
15+
:file-size="512"
16+
:max-w-h="1080"
17+
class="upload-btn"
18+
@on-success="getTableData"
1619
/>
1720

18-
1921
<el-form ref="searchForm" :inline="true" :model="search">
2022
<el-form-item label="">
21-
<el-input v-model="search.keyword" class="keyword" placeholder="请输入文件名或备注"/>
23+
<el-input v-model="search.keyword" class="keyword" placeholder="请输入文件名或备注" />
2224
</el-form-item>
2325

2426
<el-form-item>
@@ -31,7 +33,7 @@
3133
<el-table :data="tableData">
3234
<el-table-column align="left" label="预览" width="100">
3335
<template #default="scope">
34-
<CustomPic pic-type="file" :pic-src="scope.row.url"/>
36+
<CustomPic pic-type="file" :pic-src="scope.row.url" />
3537
</template>
3638
</el-table-column>
3739
<el-table-column align="left" label="日期" prop="UpdatedAt" width="180">
@@ -41,15 +43,15 @@
4143
</el-table-column>
4244
<el-table-column align="left" label="文件名/备注" prop="name" width="180">
4345
<template #default="scope">
44-
<div class="name" @click="editFileNameFunc(scope.row)">{{scope.row.name}}</div>
46+
<div class="name" @click="editFileNameFunc(scope.row)">{{ scope.row.name }}</div>
4547
</template>
4648
</el-table-column>
47-
<el-table-column align="left" label="链接" prop="url" min-width="300"/>
49+
<el-table-column align="left" label="链接" prop="url" min-width="300" />
4850
<el-table-column align="left" label="标签" prop="tag" width="100">
4951
<template #default="scope">
5052
<el-tag
51-
:type="scope.row.tag === 'jpg' ? 'primary' : 'success'"
52-
disable-transitions
53+
:type="scope.row.tag === 'jpg' ? 'primary' : 'success'"
54+
disable-transitions
5355
>{{ scope.row.tag }}
5456
</el-tag>
5557
</template>
@@ -63,14 +65,14 @@
6365
</el-table>
6466
<div class="gva-pagination">
6567
<el-pagination
66-
:current-page="page"
67-
:page-size="pageSize"
68-
:page-sizes="[10, 30, 50, 100]"
69-
:style="{ float: 'right', padding: '20px' }"
70-
:total="total"
71-
layout="total, sizes, prev, pager, next, jumper"
72-
@current-change="handleCurrentChange"
73-
@size-change="handleSizeChange"
68+
:current-page="page"
69+
:page-size="pageSize"
70+
:page-sizes="[10, 30, 50, 100]"
71+
:style="{ float: 'right', padding: '20px' }"
72+
:total="total"
73+
layout="total, sizes, prev, pager, next, jumper"
74+
@current-change="handleCurrentChange"
75+
@size-change="handleSizeChange"
7476
/>
7577
</div>
7678
</div>
@@ -85,6 +87,7 @@ import CustomPic from '@/components/customPic/index.vue'
8587
import UploadImage from '@/components/upload/image.vue'
8688
import UploadCommon from '@/components/upload/common.vue'
8789
import { formatDate } from '@/utils/format'
90+
import warningBar from '@/components/warningBar/warningBar.vue'
8891
8992
import { ref } from 'vue'
9093
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -130,25 +133,25 @@ const deleteFileFunc = async(row) => {
130133
cancelButtonText: '取消',
131134
type: 'warning',
132135
})
133-
.then(async() => {
134-
const res = await deleteFile(row)
135-
if (res.code === 0) {
136-
ElMessage({
137-
type: 'success',
138-
message: '删除成功!',
139-
})
140-
if (tableData.value.length === 1 && page.value > 1) {
141-
page.value--
142-
}
143-
getTableData()
144-
}
145-
})
146-
.catch(() => {
136+
.then(async() => {
137+
const res = await deleteFile(row)
138+
if (res.code === 0) {
147139
ElMessage({
148-
type: 'info',
149-
message: '已取消删除',
140+
type: 'success',
141+
message: '删除成功!',
150142
})
143+
if (tableData.value.length === 1 && page.value > 1) {
144+
page.value--
145+
}
146+
getTableData()
147+
}
148+
})
149+
.catch(() => {
150+
ElMessage({
151+
type: 'info',
152+
message: '已取消删除',
151153
})
154+
})
152155
}
153156
154157
const downloadFile = (row) => {
@@ -170,10 +173,10 @@ const editFileNameFunc = async(row) => {
170173
cancelButtonText: '取消',
171174
inputPattern: /\S/,
172175
inputErrorMessage: '不能为空',
173-
inputValue: row.name
176+
inputValue: row.name
174177
}).then(async({ value }) => {
175-
row.name = value;
176-
//console.log(row)
178+
row.name = value
179+
// console.log(row)
177180
const res = await editFileName(row)
178181
if (res.code === 0) {
179182
ElMessage({
@@ -186,8 +189,8 @@ const editFileNameFunc = async(row) => {
186189
ElMessage({
187190
type: 'info',
188191
message: '取消修改'
189-
});
190-
});
192+
})
193+
})
191194
}
192195
</script>
193196
@@ -198,9 +201,10 @@ export default {
198201
}
199202
</script>
200203
<style scoped>
201-
.name{
204+
.name {
202205
cursor: pointer;
203206
}
207+
204208
.upload-btn + .upload-btn {
205209
margin-left: 12px;
206210
}

0 commit comments

Comments
 (0)