Skip to content

Commit

Permalink
Merge pull request #5 from PasteUs/dev
Browse files Browse the repository at this point in the history
release-v0.0.1 ready
  • Loading branch information
LucienShui authored Nov 26, 2019
2 parents c20d870 + b08a8a1 commit 5e2b969
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name-template: 'release-v$NEXT_PATCH_VERSION'
tag-template: 'release-v$NEXT_PATCH_VERSION'
categories:
- title: 'Features'
labels:
- 'feature'
- 'enhancement'
- title: 'Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: 'Maintenance'
labels:
- 'chore'
- 'documentation'
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
template: |
# Changes
$CHANGES
17 changes: 17 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release Drafter

on:
push:
branches:
- master

jobs:
draft_release:
if: github.repository == 'PasteUs/PasteMeLite'
name: Draft release
runs-on: ubuntu-latest
steps:
- uses: toolmantim/[email protected]
name: Draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/update-submodule-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Update submodule

on:
schedule:
- cron: "*/5 * * * *"

jobs:
update:
if: github.repository == 'PasteUs/PasteMeLite'
name: Update submodule
runs-on: ubuntu-latest

steps:
- name: Clone and update submodule
run: |
git clone https://github.com/${{ github.repository }}.git -b dev PasteMeDev --recursive
cd PasteMeDev
git submodule foreach git pull origin master
git config user.name "Lucien Shui"
git config user.email "[email protected]"
git add --all
if ! git commit -m "Sync submodule at `TZ=UTC-8 date +'%Y-%m-%d %H:%M:%S'`"; then exit 0; fi
git push https://"${{ secrets.GITHUB_PASSWORD }}"@"github.com/${{ github.repository }}.git" dev
73 changes: 73 additions & 0 deletions .github/workflows/upload-to-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: PasteMe Lite Release

on:
release:
types: [published]

jobs:

release:
if: github.repository == 'PasteUs/PasteMeLite'
name: Release on ${{ matrix.os }} and upload
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
node_version: [12.x]
go_version: [1.13]

steps:
- uses: actions/checkout@v1

- name: Set up Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node_version: ${{ matrix.node_version }}

- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go_version }}
id: go

- name: Update submodule
run: |
git submodule update --init --recursive
- name: Build Frontend
run: |
cp vue.config.js PasteMeFrontend
cd PasteMeFrontend
npm install
npm run build
mv pasteme_frontend/usr/config.example.json pasteme_frontend/usr/config.json
rm -rf pasteme_frontend/conf.d pasteme_frontend/report.html
cd ..
- name: Build Backend
run: |
cp server.go PasteMeGoBackend
cd PasteMeGoBackend
go mod download
go build main.go
cd ..
env:
GO111MODULE: on
GOPROXY: https://goproxy.io
GOOS: linux

- name: Gzip
run: |
mkdir pasteme_lite
cp doc/DEPLOY.md pasteme_lite/README.md
cp -r PasteMeFrontend/pasteme_frontend pasteme_lite
cp PasteMeGoBackend/main pasteme_lite/pastemed
tar -czvf pasteme_lite.tar.gz pasteme_lite
- name: Upload to release
uses: JasonEtco/upload-to-release@master
with:
args: pasteme_lite.tar.gz application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "PasteMeFrontend"]
path = PasteMeFrontend
url = https://github.com/PasteUs/PasteMeFrontend.git
[submodule "PasteMeGoBackend"]
path = PasteMeGoBackend
url = https://github.com/PasteUs/PasteMeGoBackend.git
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:12 as frontend_builder
COPY ./PasteMeFrontend /source
COPY ./vue.config.js /source/vue.config.js
WORKDIR /source
RUN npm install --registry=https://registry.npm.taobao.org
RUN npm run build
RUN mv pasteme_frontend/usr/config.example.json pasteme_frontend/usr/config.json
RUN rm -rf pasteme_frontend/conf.d pasteme_frontend/report.html

FROM golang:1.13-alpine as backend_builder
COPY ./PasteMeGoBackend /go/src/github.com/PasteUs/PasteMeGoBackend
COPY ./server.go /go/src/github.com/PasteUs/PasteMeGoBackend/server/server.go
ENV GO111MODULE=on \
GOPROXY=https://goproxy.io \
GOOS=linux
WORKDIR /go/src/github.com/PasteUs/PasteMeGoBackend
RUN apk --no-cache add g++
RUN go mod download
RUN go build main.go

FROM alpine:3
LABEL maintainer="Lucien Shui" \
email="[email protected]"
COPY --from=backend_builder /go/src/github.com/PasteUs/PasteMeGoBackend/main /usr/bin/pastemed
COPY --from=frontend_builder /source/pasteme_frontend /pasteme_frontend
RUN chmod +x /usr/bin/pastemed && \
mkdir /data && \
mkdir /config && \
echo '{"address":"0.0.0.0","port":8000,"database":{"type":"sqlite","username":"username","password":"password","server":"pasteme-mysql","port":3306,"database":"pasteme"}}' > /config/config.json
CMD ["pastemed", "-c", "/config/config.json", "-d", "/data"]
1 change: 1 addition & 0 deletions PasteMeFrontend
Submodule PasteMeFrontend added at 1e505b
1 change: 1 addition & 0 deletions PasteMeGoBackend
Submodule PasteMeGoBackend added at 78cb82
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# PasteMeLite
PasteMe lite version, executing is all you need to do.
<p align="center">
<img src="https://cdn.jsdelivr.net/gh/PasteUs/[email protected]/screenshot/pasteme/duck.png" alt="" width=200>
</p>
<p align="center">
<a href="./doc/DEPLOY.md">
<img src="https://img.shields.io/badge/pasteme__lite.tar.gz-20.5MB-green.svg" alt="version">
</a>
<a href="./doc/DEPLOY.md">
<img src="https://img.shields.io/badge/docker_image-48.1MB-darkgreen.svg" alt="version">
</a>
</p>
<p align="center">
<a href="./LICENSE">
<img src="https://img.shields.io/eclipse-marketplace/l/notepad4e.svg" alt="">
</a>
<a href="https://github.com/PasteUs/PasteMeFrontend">
<img src="https://img.shields.io/badge/Frontend-3.1.0-brightgreen.svg" alt="version">
</a>
<a href="https://github.com/PasteUs/PasteMeBackend">
<img src="https://img.shields.io/badge/Backend-3.2.1-lightblue.svg" alt="version">
</a>
<a href="#谢谢老板">
<img src="https://img.shields.io/badge/%24-donate-ff69b4.svg" alt="donate">
</a>
</p>
<div align="center">
<h1>PasteMe Lite</h1>
</div>

[PasteMe](https://github.com/LucienShui/PasteMe) 的轻量版本,将前端集成至 Golang 服务中,不依赖于数据库服务。唯一一件需要做的事情,就是运行。

## Deploy

[PasteMe Lite Deploy Documentation](./doc/DEPLOY.md)
21 changes: 21 additions & 0 deletions doc/DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PasteMe Lite 部署文档

## 直接运行

> 由于 sqlite 使用了 cgo,故目前只支持 linux-amd64
前往此项目的 [latest release](https://github.com/PasteUs/PasteMeLite/releases/latest) 页面下载 `pasteme_lite.tar.gz` ,解压后执行 `./pastemed` 即可。

## Docker

```bash
docker run \
-d \
-p 80:8000 \
-v ${PWD}/backend/data/:/data/ \
registry.cn-hangzhou.aliyuncs.com/pasteus/pasteme-lite:0.0.1
```

## docker-compose

[docker-compose.yml](../docker-compose.yml)
17 changes: 17 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

services:
pasteme-lite:
build: .
container_name: pasteme-lite
healthcheck:
test: ["CMD", "wget", "localhost:8000/?method=beat", "--output=/dev/null"]
interval: 45s
timeout: 3s
retries: 3
restart: always
volumes:
- ./backend/data/:/data/
#- ./frontend/usr/:/pasteme_frontend/usr/
ports:
- 80:8000
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

services:
pasteme-lite:
image: registry.cn-hangzhou.aliyuncs.com/pasteus/pasteme-lite:0.0.1
container_name: pasteme-lite
healthcheck:
test: ["CMD", "wget", "localhost:8000/?method=beat", "--output=/dev/null"]
interval: 45s
timeout: 3s
retries: 3
restart: always
volumes:
- ./backend/data/:/data/
#- ./frontend/usr/:/pasteme_frontend/usr/
ports:
- 80:8000
49 changes: 49 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
@File: server.go
@Contact: [email protected]
@Licence: (C)Copyright 2019 Lucien Shui
@Modify Time @Author @Version @Description
------------ ------- -------- -----------
2019-06-21 08:37 Lucien 1.0 Init
*/
package server

import (
"fmt"
"github.com/PasteUs/PasteMeGoBackend/flag"
"github.com/gin-gonic/gin"
"github.com/wonderivan/logger"
)

var router *gin.Engine

func init() {
if !flag.Debug {
gin.SetMode(gin.ReleaseMode)
}
router = gin.Default()

api := router.Group("/api")
{
api.GET("/", beat)
api.GET("/:token", query)
api.POST("/", permanentCreator)
api.POST("/once", readOnceCreator)
api.PUT("/:key", temporaryCreator)
// router.NoRoute(notFoundHandler)
}

router.Static("/pasteme_frontend/", "pasteme_frontend/")
router.Static("/usr/", "pasteme_frontend/usr/")

router.NoRoute(func(requests *gin.Context) {
requests.File("pasteme_frontend/index.html")
})
}

func Run(address string, port uint16) {
if err := router.Run(fmt.Sprintf("%s:%d", address, port)); err != nil {
logger.Painc("Run server failed: " + err.Error())
}
}
Loading

0 comments on commit 5e2b969

Please sign in to comment.