Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jul 1, 2023
0 parents commit 3371d64
Show file tree
Hide file tree
Showing 99 changed files with 10,649 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -tags dev -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main server -vv"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "vue", "js", "css", "woff", "ttf"]
# Ignore these filename extensions or directories.
exclude_dir = ["tmp", "libs", "vendor", "view"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# Exclude unchanged files.
exclude_unchanged = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = false
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.next
.vscode
.git
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
static/** linguist-vendored
static/js/router.js -linguist-vendored
static/css/main.css -linguist-vendored
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "🏗️ Build"
# trigger events
on:
push:
branches:
- "**"
pull_request:
workflow_dispatch:

jobs:
build:
strategy:
matrix:
go_version: [1.18.x]

runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
- uses: actions/setup-node@v2
with:
node-version: "16"
- uses: actions/checkout@v3
- name: build frontend
run: cd ./view && npm install && npm run build
- uses: golangci/golangci-lint-action@v3
with:
version: v1.53.2
args: --out-format=colored-line-number --timeout=5m
- run: go mod download
- run: go test -coverprofile=coverage.txt -covermode=atomic ./...
35 changes: 35 additions & 0 deletions .github/workflows/clean_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Attention:
# - Need goto [Settings -> Secrets -> Actions]
# - Add a [PAT] secrets as GitHub Personal access token
name: "🗑️ Clean Package"

# Controls when the workflow will run
on:
schedule:
- cron: "0 0 1 * *" # the first day of the month

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
clean-up:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Initialize workflow variables
id: vars
run: |
echo "APP_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
- name: Delete old images
uses: snok/container-retention-policy@v2
with:
image-names: ${{steps.vars.outputs.APP_NAME}}
cut-off: A week ago UTC
keep-at-least: 2
skip-tags: latest
account-type: personal
token: ${{ secrets.PAT }}
21 changes: 21 additions & 0 deletions .github/workflows/issue_close_inactive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "🚫 Close Inactive"

on:
# schedule:
# - cron: "0 0 * * 1"
workflow_dispatch:

jobs:
close-inactive:
runs-on: ubuntu-latest
steps:
- name: close-issues
uses: actions-cool/issues-helper@v3
with:
actions: "close-issues"
token: ${{ secrets.GITHUB_TOKEN }}
inactive-day: 30
exclude-labels: "enhancement,bug"
close-reason: "not_planned"
body: |
This issue was closed due to inactive more than 30 days. You can reopen it if you think it should continue.
127 changes: 127 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Attention:
# - Need goto [Settings -> Actions -> general]
# - Set [workflow permissions] to "Read and write permissions"
name: "🚀 Release"

# on events
on:
push:
tags: ["v*"]

# jobs
jobs:
# generate build cross-platform build files
release:
name: Generate cross-platform builds
strategy:
matrix:
go_version: [1.18.x]
runs-on: ubuntu-latest
steps:
# step 1: checkout repository code
- name: Checkout the repository
uses: actions/checkout@v3

# step 2: setup build envirement
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
- uses: actions/setup-node@v2
with:
node-version: "16"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# step 3: set workflow variables
- name: Initialize workflow variables
id: vars
run: |
echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT
echo "BUILDDATE=$(date '+%F-%T')" >> $GITHUB_OUTPUT
echo "COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
echo "APP_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
echo "REPO=$(echo 'github.com/${{ github.repository }}')" >> $GITHUB_OUTPUT
echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_OUTPUT
if [ ! -z $DOCKER_TOKEN ]; then echo "HAS_DOCKER_TOKEN=${HAS_DOCKER_TOKEN}" >> $GITHUB_OUTPUT; fi
env:
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}"

# step 4: generate build files
- name: build frontend
run: cd ./view && npm install && npm run build
- name: Generate build files
uses: crazy-max/ghaction-xgo@v2
with:
xgo_version: latest
go_version: ${{ matrix.go_version }}
dest: build
prefix: ${{steps.vars.outputs.APP_NAME}}
targets: linux/amd64
v: true
x: false
ldflags: -w -s -X ${{steps.vars.outputs.REPO}}/internal/version.Version=${{steps.vars.outputs.VERSION}} -X ${{steps.vars.outputs.REPO}}/internal/version.BuildDate=${{steps.vars.outputs.BUILDDATE}} -X ${{steps.vars.outputs.REPO}}/internal/version.Commit=${{steps.vars.outputs.COMMIT}} -X ${{steps.vars.outputs.REPO}}/internal/mode.Mode=production

# step 5: compress build files
- name: Compress build files
run: cd ./build && for i in *; do tar -czf $i.tar.gz $i; done && cd ..

# step 6: Upload binary to GitHub Release
- name: Upload binary to GitHub Release
uses: softprops/action-gh-release@v1
if: "startsWith(github.ref, 'refs/tags/')"
with:
files: |
./build/*.tar.gz
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
generate_release_notes: true
fail_on_unmatched_files: true

# step 7.1: push to DockerHub
- name: Login to DockerHub
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN == 'true' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push Docker images to DockerHub
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN == 'true' }}
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:latest
build-args: |
APP_NAME=${{steps.vars.outputs.APP_NAME}}
VERSION=${{steps.vars.outputs.VERSION}}
BUILDDATE=${{steps.vars.outputs.BUILDDATE}}
COMMIT=${{steps.vars.outputs.COMMIT}}
# step 7.2: push to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker images to ghci
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_NAME=${{steps.vars.outputs.APP_NAME}}
VERSION=${{steps.vars.outputs.VERSION}}
BUILDDATE=${{steps.vars.outputs.BUILDDATE}}
COMMIT=${{steps.vars.outputs.COMMIT}}
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
**/.DS_Store
**/coverage.txt

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/
tmp/
dist/
build/
node_modules/
go-docker-skeleton
main
AltServerData/
atvloadly
81 changes: 81 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
env:
- GO111MODULE=on

build:
# env:
# - CGO_ENABLED=0
ldflags:
- -w -s -X main.Version={{ .Version }} -X main.BuildDate={{ .Date }} -X main.Commit={{ .FullCommit }} -X main.Mode=prod
binary: "{{.ProjectName}}"
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: 386

archives:
- name_template: "{{.ProjectName}}-{{.Os}}-{{.Arch}}"
format: tar.gz
format_overrides:
- goos: windows
format: zip

dockers:
- image_templates:
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"
- "--build-arg=APP_NAME={{.ProjectName}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=BUILDDATE={{.Date}}"
- "--build-arg=COMMIT={{.FullCommit}}"
- image_templates:
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
- "--build-arg=APP_NAME={{.ProjectName}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=BUILDDATE={{.Date}}"
- "--build-arg=COMMIT={{.FullCommit}}"
goarch: arm64

docker_manifests:
# - name_template: "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}"
# image_templates:
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}"
image_templates:
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
# - name_template: "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:latest"
# image_templates:
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
# - "{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
- name_template: "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:latest"
image_templates:
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-amd64"
- "ghcr.io/{{ .Env.GIT_OWER }}/{{ .Env.GIT_REPO }}:{{ .Tag }}-arm64"
Loading

0 comments on commit 3371d64

Please sign in to comment.