Skip to content

Commit

Permalink
Add a GitHub Actions workflow for CI testing
Browse files Browse the repository at this point in the history
Also adjusts the server so TLS is now optional (thus no need for
certs), and also adds a script to grab the release files from our
GitHub repo so they're present for the tests.
  • Loading branch information
justinclift committed Jan 4, 2024
1 parent 9fa3ae9 commit d5482db
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 19 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

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

- name: Build
run: go build -v ./...

- name: Download data files from GitHub
run: sh ./grab_datafiles.sh

- name: Test
run: go test -v ./...
env:
CONFIG_FILE: config/downloader_config.toml
17 changes: 9 additions & 8 deletions config/downloader_config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[jaeger]
CollectorEndPoint = "http://jaeger_server_name:14268/api/traces"
enable = false

[paths]
baseDir = "/path to/go/src/github.com/sqlitebrowser/db4s_cluster_downloader"
certDir = "/path to your letsencrypt certificate dir"
dataDir = "/path to the directory holding the download files"
baseDir = "./"
dataDir = "./data"

[pg]
database = "db4s_stats"
Expand All @@ -17,4 +12,10 @@ ssl = true
username = "youruser"

[server]
port = 443
debug = false
port = 9080
sslport = 9443

[tls]
certfile = ""
keyfile = ""
41 changes: 41 additions & 0 deletions grab_datafiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env sh

# This is a simple script to download the DB4S release files from GitHub, so they're present for the GitHub Actions
# based Go test workflow

mkdir data
cd data
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.10.1/DB.Browser.for.SQLite-3.10.1-win32.exe
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.10.1/DB.Browser.for.SQLite-3.10.1-win64.exe
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.10.1/DB.Browser.for.SQLite-3.10.1.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.10.1/SQLiteDatabaseBrowserPortable_3.10.1_English.paf.exe
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.0/DB.Browser.for.SQLite-3.11.0-win32.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.0/DB.Browser.for.SQLite-3.11.0-win32.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.0/DB.Browser.for.SQLite-3.11.0-win64.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.0/DB.Browser.for.SQLite-3.11.0-win64.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.0/DB.Browser.for.SQLite-3.11.0.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.1/DB.Browser.for.SQLite-3.11.1-win32.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.1/DB.Browser.for.SQLite-3.11.1-win32.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.1/DB.Browser.for.SQLite-3.11.1-win64.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.1/DB.Browser.for.SQLite-3.11.1-win64.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.1/DB.Browser.for.SQLite-3.11.1v2.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/DB.Browser.for.SQLite-3.11.2-win32.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/DB.Browser.for.SQLite-3.11.2-win32.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/DB.Browser.for.SQLite-3.11.2-win64.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/DB.Browser.for.SQLite-3.11.2-win64.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/DB.Browser.for.SQLite-3.11.2.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.11.2/SQLiteDatabaseBrowserPortable_3.11.2_Rev_2_English.paf.exe
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/DB.Browser.for.SQLite-3.12.0-win32.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/DB.Browser.for.SQLite-3.12.0-win32.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/DB.Browser.for.SQLite-3.12.0-win64.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/DB.Browser.for.SQLite-3.12.0-win64.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/DB.Browser.for.SQLite-3.12.0.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.0/SQLiteDatabaseBrowserPortable_3.12.0_English.paf.exe
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2-win32.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2-win32.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2-win64.msi
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2-win64.zip
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-arm64-3.12.2.dmg
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB_Browser_for_SQLite-v3.12.2-x86_64.AppImage
curl -sOL https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/SQLiteDatabaseBrowserPortable_3.12.2_English.paf.exe
27 changes: 19 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,32 @@ func main() {
log.Fatal(err)
}

// Create the HTTPS server configuration
// Create the basic HTTP server configuration
s := &http.Server{
Addr: fmt.Sprintf(":%d", Conf.Server.Port),
ErrorLog: HttpErrorLog(),
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12, // TLS 1.2 is now the lowest acceptable level
},
}

// Start the server
log.Printf("Listening on port %d...", Conf.Server.Port)
err = s.ListenAndServeTLS(filepath.Join(Conf.Paths.CertDir, "fullchain.pem"), filepath.Join(Conf.Paths.CertDir, "privkey.pem"))
// If TLS Cert and key file paths are given, then we're using TLS
if Conf.TLS.CertFile != "" && Conf.TLS.KeyFile != "" {
s.Addr = fmt.Sprintf(":%d", Conf.Server.SSLPort)
s.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12, // TLS 1.2 is now the lowest acceptable level
}
log.Printf("Listening on port %d...", Conf.Server.SSLPort)

// Start the server
err = s.ListenAndServeTLS(filepath.Join(Conf.TLS.CertFile), filepath.Join(Conf.TLS.KeyFile))
} else {
// Not using TLS (eg for testing on GitHub Actions)
s.Addr = fmt.Sprintf(":%d", Conf.Server.Port)
log.Printf("Listening on port %d...", Conf.Server.Port)

// Start the server
err = s.ListenAndServe()
}
if err != nil {
log.Fatal(err)
}
Expand Down
12 changes: 9 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type TomlConfig struct {
Paths PathInfo
Pg PGInfo
Server ServerInfo
TLS TLSInfo
}
type PathInfo struct {
BaseDir string // Location of the git source
CertDir string // Location of the TLS certificates
DataDir string // Directory where the downloads are located
}
type PGInfo struct {
Expand All @@ -23,8 +23,14 @@ type PGInfo struct {
Username string
}
type ServerInfo struct {
Debug bool
Port int
Debug bool
Port int
SSLPort int
}

type TLSInfo struct {
CertFile string // Full path of the TLS certificate file
KeyFile string // Full path of the TLS private key file
}

// dbEntry is used for storing the new database entries
Expand Down

0 comments on commit d5482db

Please # to comment.