add deploy files
This commit is contained in:
parent
a6338a36ea
commit
16326daf66
12
.dockerignore
Normal file
12
.dockerignore
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
media/
|
||||||
|
upload/
|
||||||
|
log/
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
Makefile
|
||||||
|
modd.conf
|
||||||
|
sqlc.yaml
|
||||||
|
docker-compose.yaml
|
||||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Build Stage
|
||||||
|
FROM golang:1.21.4 AS builder
|
||||||
|
ENV GO111MODULE=on \
|
||||||
|
GOPROXY=https://goproxy.cn,direct
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main main.go
|
||||||
|
|
||||||
|
# Run Stage
|
||||||
|
FROM zc1185230223/alpine-ffmpeg:3.18
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/main .
|
||||||
|
RUN touch app.env
|
||||||
|
EXPOSE 9090
|
||||||
|
CMD ["/app/main"]
|
||||||
20
docker-compose.yaml
Normal file
20
docker-compose.yaml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
version: '3.9'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mediahls:
|
||||||
|
image: mediahls:0.0.3
|
||||||
|
container_name: mediahls
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- /var/mediahls/app/log:/app/log
|
||||||
|
- /var/mediahls/app/app.env:/app/app.env
|
||||||
|
- /var/mediahls/app/media:/app/media
|
||||||
|
- /var/mediahls/app/upload:/app/upload
|
||||||
|
networks:
|
||||||
|
- media-hls-network
|
||||||
|
ports:
|
||||||
|
- "10050:9090"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
media-hls-network:
|
||||||
|
external: true
|
||||||
@ -26,7 +26,6 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
templateFS fs.FS
|
templateFS fs.FS
|
||||||
staticFS fs.FS
|
staticFS fs.FS
|
||||||
imgFS fs.FS
|
|
||||||
|
|
||||||
conf *config.Config
|
conf *config.Config
|
||||||
router *mux.Router
|
router *mux.Router
|
||||||
@ -36,7 +35,7 @@ type Server struct {
|
|||||||
tokenMaker token.Maker
|
tokenMaker token.Maker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(templateFS fs.FS, staticFS fs.FS, imgFS fs.FS, conf *config.Config, store db.Store) (*Server, error) {
|
func NewServer(templateFS fs.FS, staticFS fs.FS, conf *config.Config, store db.Store) (*Server, error) {
|
||||||
tokenMaker, err := token.NewPasetoMaker(conf.TokenSymmetricKey)
|
tokenMaker, err := token.NewPasetoMaker(conf.TokenSymmetricKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create token maker: %w", err)
|
return nil, fmt.Errorf("cannot create token maker: %w", err)
|
||||||
@ -50,7 +49,6 @@ func NewServer(templateFS fs.FS, staticFS fs.FS, imgFS fs.FS, conf *config.Confi
|
|||||||
server := &Server{
|
server := &Server{
|
||||||
templateFS: templateFS,
|
templateFS: templateFS,
|
||||||
staticFS: staticFS,
|
staticFS: staticFS,
|
||||||
imgFS: imgFS,
|
|
||||||
conf: conf,
|
conf: conf,
|
||||||
secureCookie: secureCookie,
|
secureCookie: secureCookie,
|
||||||
store: store,
|
store: store,
|
||||||
@ -65,7 +63,7 @@ func (server *Server) setupRouter() {
|
|||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Use(mux.CORSMethodMiddleware(router))
|
router.Use(mux.CORSMethodMiddleware(router))
|
||||||
router.PathPrefix("/statics/").Handler(http.StripPrefix("/statics/", http.FileServer(http.FS(server.staticFS))))
|
router.PathPrefix("/statics/").Handler(http.StripPrefix("/statics/", http.FileServer(http.FS(server.staticFS))))
|
||||||
router.PathPrefix("/upload/imgs").Handler(http.StripPrefix("/upload/imgs/", http.FileServer(http.FS(server.imgFS))))
|
router.PathPrefix("/upload/imgs").Handler(http.StripPrefix("/upload/imgs/", http.FileServer(http.Dir("./upload/imgs"))))
|
||||||
|
|
||||||
csrfMiddleware := csrf.Protect(
|
csrfMiddleware := csrf.Protect(
|
||||||
[]byte(securecookie.GenerateRandomKey(32)),
|
[]byte(securecookie.GenerateRandomKey(32)),
|
||||||
|
|||||||
11
main.go
11
main.go
@ -18,9 +18,6 @@ var templateFS embed.FS
|
|||||||
//go:embed web/statics
|
//go:embed web/statics
|
||||||
var staticFS embed.FS
|
var staticFS embed.FS
|
||||||
|
|
||||||
//go:embed upload/imgs
|
|
||||||
var imgFS embed.FS
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// filename, _ := nanoId.Nanoid()
|
// filename, _ := nanoId.Nanoid()
|
||||||
// log.Println(filename)
|
// log.Println(filename)
|
||||||
@ -38,12 +35,6 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up imgs
|
|
||||||
imgs, err := fs.Sub(imgFS, "upload/imgs")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := config.LoadConfig(".")
|
config, err := config.LoadConfig(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("cannot load config: ", err)
|
log.Fatal("cannot load config: ", err)
|
||||||
@ -57,7 +48,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store := db.NewStore(conn)
|
store := db.NewStore(conn)
|
||||||
server, err := handlers.NewServer(templates, statics, imgs, config, store)
|
server, err := handlers.NewServer(templates, statics, config, store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("cannot create server: ", err)
|
log.Fatal("cannot create server: ", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,6 +109,7 @@
|
|||||||
{{define "js"}}
|
{{define "js"}}
|
||||||
<script>
|
<script>
|
||||||
function uploadImage() {
|
function uploadImage() {
|
||||||
|
let csrfToken = $('input[name="csrf_token"]').val()
|
||||||
var files = $('#upload_images').prop('files');
|
var files = $('#upload_images').prop('files');
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append('file', files[0]);
|
data.append('file', files[0]);
|
||||||
@ -120,6 +121,9 @@
|
|||||||
cache: false,
|
cache: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
headers: {
|
||||||
|
"X-CSRF-Token": csrfToken
|
||||||
|
},
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
$('#images').val(res);
|
$('#images').val(res);
|
||||||
$('.image-box').append('<img width="120px" src="' + res + '" />');
|
$('.image-box').append('<img width="120px" src="' + res + '" />');
|
||||||
@ -127,6 +131,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
function uploadVideo() {
|
function uploadVideo() {
|
||||||
|
let csrfToken = $('input[name="csrf_token"]').val()
|
||||||
var files = $('#upload_video').prop('files');
|
var files = $('#upload_video').prop('files');
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append('file', files[0]);
|
data.append('file', files[0]);
|
||||||
@ -138,6 +143,9 @@
|
|||||||
cache: false,
|
cache: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
headers: {
|
||||||
|
"X-CSRF-Token": csrfToken
|
||||||
|
},
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
$('#video').val(res);
|
$('#video').val(res);
|
||||||
$('#upload_video_msg').html('上传成功')
|
$('#upload_video_msg').html('上传成功')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user