Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
ci: add release and docker workflows (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baconing authored Dec 18, 2023
2 parents 0050a14 + 6cbe6b9 commit fdf18a8
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 22 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Docker

on:
push:
branches:
- master
- develop
release:
types:
- published

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=${{ github.event_name == 'release' && github.event.release.prerelease == false }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'release' && github.event.release.prerelease == false }}
type=raw,value=nightly,enable=${{ github.event_name == 'release' && github.event.release.prerelease == true }}
type=ref,enable=true,event=branch
type=raw,value=${{ github.event.release.tag_name }},enable=${{ github.event_name == 'release' }}
type=raw,value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
79 changes: 79 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release

on:
push:
tags:
- v*

jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v -o ./tmp/beeapi-linux-amd64 ./main.go

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: beeapi-linux-amd64
path: ./tmp/beeapi-linux-amd64

build-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v -o ./tmp/beeapi-windows-amd64.exe ./main.go

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: beeapi-windows-amd64.exe
path: ./tmp/beeapi-windows-amd64.exe

publish:
needs: [build-linux, build-windows]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Linux Build Artifact
uses: actions/download-artifact@v4
with:
name: beeapi-linux-amd64
path: ./builds

- name: Download Windows Build Artifact
uses: actions/download-artifact@v4
with:
name: beeapi-windows-amd64.exe
path: ./builds

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
./build/beeapi-linux-amd64
./build/beeapi-windows-amd64.exe
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body: |
Automated release, please set a proper body before publishing.
draft: true
prerelease: ${{ contains(github.ref, 'pre') || contains(github.ref, 'prerelease') }}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.20 AS build
WORKDIR /build
COPY go.mod go.sum /build/
RUN go mod download
COPY . /build/
RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/beeapi-linux-amd64 ./main.go

FROM alpine:latest
COPY --from=build /tmp/beeapi-linux-amd64 /app/beeapi
WORKDIR /app
CMD ["/app/beeapi"]
12 changes: 8 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
//go:embed config.yml
var defaultConfigFile []byte

var Configuration *Config
var conf *Config

const (
DefaultConfigFilePath = "/etc/beeapi/config.yml"
Expand All @@ -28,8 +28,8 @@ type Config struct {
Development bool `yaml:"development"`
}

func GenerateConfig() {
Configuration = &Config{}
func Init() {
conf = &Config{}

configFile, err := os.Open(DefaultConfigFilePath)

Expand All @@ -38,7 +38,7 @@ func GenerateConfig() {
panic("Created config file. Please edit it and restart the application.")
}

err = yaml.NewDecoder(configFile).Decode(Configuration)
err = yaml.NewDecoder(configFile).Decode(conf)

if err != nil {
panic(err)
Expand Down Expand Up @@ -69,3 +69,7 @@ func createConfigFile() {
panic(err)
}
}

func GetConfig() *Config {
return conf
}
8 changes: 4 additions & 4 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ var mdls = []interface{}{

func Init() {
cfg := mysql2.NewConfig()
cfg.User = config.Configuration.Database.User
cfg.Passwd = config.Configuration.Database.Password
cfg.User = config.GetConfig().Database.User
cfg.Passwd = config.GetConfig().Database.Password
cfg.Net = "tcp"
cfg.Addr = config.Configuration.Database.Host + ":" + strconv.Itoa(config.Configuration.Database.Port)
cfg.DBName = config.Configuration.Database.Name
cfg.Addr = config.GetConfig().Database.Host + ":" + strconv.Itoa(config.GetConfig().Database.Port)
cfg.DBName = config.GetConfig().Database.Name
cfg.ParseTime = true
cfg.MultiStatements = true

Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
beeapi:
image: ghcr.io/frc5183/beeapi:latest
restart: always
ports:
- 8080:8080
volumes:
- ./config:/etc/beeapi
34 changes: 26 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
module beeapi

go 1.20
go 1.21

toolchain go1.21.4

require (
github.com/gin-gonic/gin v1.9.1
github.com/go-sql-driver/mysql v1.7.1
github.com/rs/zerolog v1.31.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/akamensky/argparse v1.4.0 // indirect
github.com/bep/godartsass v1.2.0 // indirect
github.com/bep/godartsass/v2 v2.0.0 // indirect
github.com/bep/golibsass v1.1.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/cosmtrek/air v1.49.0 // indirect
github.com/creack/pty v1.1.21 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gohugoio/hugo v0.121.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -24,9 +43,11 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/phuslu/log v1.0.88 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/tdewolff/parse/v2 v2.7.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.6.0 // indirect
Expand All @@ -35,7 +56,4 @@ require (
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.2 // indirect
gorm.io/gorm v1.25.5 // indirect
)
Loading

0 comments on commit fdf18a8

Please sign in to comment.