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 {
|
||||
templateFS fs.FS
|
||||
staticFS fs.FS
|
||||
imgFS fs.FS
|
||||
|
||||
conf *config.Config
|
||||
router *mux.Router
|
||||
@ -36,7 +35,7 @@ type Server struct {
|
||||
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)
|
||||
if err != nil {
|
||||
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{
|
||||
templateFS: templateFS,
|
||||
staticFS: staticFS,
|
||||
imgFS: imgFS,
|
||||
conf: conf,
|
||||
secureCookie: secureCookie,
|
||||
store: store,
|
||||
@ -65,7 +63,7 @@ func (server *Server) setupRouter() {
|
||||
router := mux.NewRouter()
|
||||
router.Use(mux.CORSMethodMiddleware(router))
|
||||
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(
|
||||
[]byte(securecookie.GenerateRandomKey(32)),
|
||||
|
||||
11
main.go
11
main.go
@ -18,9 +18,6 @@ var templateFS embed.FS
|
||||
//go:embed web/statics
|
||||
var staticFS embed.FS
|
||||
|
||||
//go:embed upload/imgs
|
||||
var imgFS embed.FS
|
||||
|
||||
func main() {
|
||||
// filename, _ := nanoId.Nanoid()
|
||||
// log.Println(filename)
|
||||
@ -38,12 +35,6 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Set up imgs
|
||||
imgs, err := fs.Sub(imgFS, "upload/imgs")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
config, err := config.LoadConfig(".")
|
||||
if err != nil {
|
||||
log.Fatal("cannot load config: ", err)
|
||||
@ -57,7 +48,7 @@ func main() {
|
||||
}
|
||||
|
||||
store := db.NewStore(conn)
|
||||
server, err := handlers.NewServer(templates, statics, imgs, config, store)
|
||||
server, err := handlers.NewServer(templates, statics, config, store)
|
||||
if err != nil {
|
||||
log.Fatal("cannot create server: ", err)
|
||||
}
|
||||
|
||||
@ -109,6 +109,7 @@
|
||||
{{define "js"}}
|
||||
<script>
|
||||
function uploadImage() {
|
||||
let csrfToken = $('input[name="csrf_token"]').val()
|
||||
var files = $('#upload_images').prop('files');
|
||||
var data = new FormData();
|
||||
data.append('file', files[0]);
|
||||
@ -120,6 +121,9 @@
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
headers: {
|
||||
"X-CSRF-Token": csrfToken
|
||||
},
|
||||
success: function (res) {
|
||||
$('#images').val(res);
|
||||
$('.image-box').append('<img width="120px" src="' + res + '" />');
|
||||
@ -127,6 +131,7 @@
|
||||
})
|
||||
}
|
||||
function uploadVideo() {
|
||||
let csrfToken = $('input[name="csrf_token"]').val()
|
||||
var files = $('#upload_video').prop('files');
|
||||
var data = new FormData();
|
||||
data.append('file', files[0]);
|
||||
@ -138,6 +143,9 @@
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
headers: {
|
||||
"X-CSRF-Token": csrfToken
|
||||
},
|
||||
success: function (res) {
|
||||
$('#video').val(res);
|
||||
$('#upload_video_msg').html('上传成功')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user