Skip to content

Commit

Permalink
Merge pull request #9 from mpuckett159/features/github-actions
Browse files Browse the repository at this point in the history
Features/GitHub actions
  • Loading branch information
mpuckett159 committed Apr 22, 2021
2 parents ce18bfa + de4fdec commit 2ebe8d2
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 109 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: lint

on:
pull_request:
branches:
- master

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
working-directory: frontend
args: --out-format=tab
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build on Release

on:
release:
types: [published]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Set up QEMU
- uses: docker/setup-qemu-action@v1
name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v1
name: Login to DockerHub
- uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push API
uses: docker/build-push-action@v2
with:
context: ./frontend
platforms: linux/amd64
push: true
tags: |
mpuckett259/stack-web-app:latest
13 changes: 13 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Compile and export binary for Go app
FROM golang:1.16.3-buster AS build

ENV GO111MODULE=auto

WORKDIR /app
COPY . /app
RUN go build -o /app/main -ldflags="-extldflags=-static" -tags sqlite_omit_load_extension

# Copy out app from build image and set execution
FROM alpine:latest
COPY --from=build /app/main /
CMD [ "/main" ]
58 changes: 29 additions & 29 deletions frontend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
// User object that describes the database table columns and is used to push the info
// back to the websocket client for speaker stack rendering
type User struct {
SpeakerPostition int16 `json:"speakerPosition"`
SpeakerId string `json:"speakerId"`
Name string `json:"name"`
SpeakerPostition int16 `json:"speakerPosition"`
SpeakerId string `json:"speakerId"`
Name string `json:"name"`
}

// Start is used to start the database, that is remove any potentially existing db files
Expand All @@ -23,7 +23,7 @@ func Start() {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "Start",
"module": "db",
"module": "db",
})

// Delete and recreate existing sqlite file just in case
Expand All @@ -42,8 +42,8 @@ func CreateTable(newTableId string) (err error) {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "CreateTable",
"module": "db",
"tableId": newTableId,
"module": "db",
"tableId": newTableId,
})

// Get sqlite db connection
Expand All @@ -57,7 +57,7 @@ func CreateTable(newTableId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": createMeetingTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error preparing statement to create meeting table")
return err
}
Expand All @@ -68,7 +68,7 @@ func CreateTable(newTableId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": createMeetingTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error executing statement to create meeting table")
return err
}
Expand All @@ -86,8 +86,8 @@ func DeleteTable(tableId string) (err error) {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "DeleteTable",
"module": "db",
"tableId": tableId,
"module": "db",
"tableId": tableId,
})

// Get sqlite db connection
Expand All @@ -101,7 +101,7 @@ func DeleteTable(tableId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": deleteMeetingTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error preparing statement to delete meeting table")
return err
}
Expand All @@ -112,7 +112,7 @@ func DeleteTable(tableId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": deleteMeetingTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error executing statement to delete meeting table")
return err
}
Expand All @@ -125,11 +125,11 @@ func DeleteTable(tableId string) (err error) {
func GetOnStack(tableId string, speakerId string, name string) (err error) {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "GetOnStack",
"module": "db",
"tableId": tableId,
"function": "GetOnStack",
"module": "db",
"tableId": tableId,
"speakerId": speakerId,
"name": name,
"name": name,
})

// Get sqlite db connection
Expand All @@ -143,7 +143,7 @@ func GetOnStack(tableId string, speakerId string, name string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": addUserToStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error preparing statement to get on stack.")
return err
}
Expand All @@ -154,7 +154,7 @@ func GetOnStack(tableId string, speakerId string, name string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": addUserToStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error executing statement to get on stack.")
return err
}
Expand All @@ -168,9 +168,9 @@ func GetOnStack(tableId string, speakerId string, name string) (err error) {
func GetOffStack(tableId string, speakerId string) (err error) {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "GetOffStack",
"module": "db",
"tableId": tableId,
"function": "GetOffStack",
"module": "db",
"tableId": tableId,
"speakerId": speakerId,
})

Expand All @@ -185,7 +185,7 @@ func GetOffStack(tableId string, speakerId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": removeUserFromStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error preparing statement to get off stack")
return err
}
Expand All @@ -196,7 +196,7 @@ func GetOffStack(tableId string, speakerId string) (err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": removeUserFromStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error executing statement to get off stack")
}

Expand All @@ -211,8 +211,8 @@ func ShowCurrentStack(tableId string) (stackUsers []User, err error) {
// Add to context logger
ContextLogger = ContextLogger.WithFields(log.Fields{
"function": "ShowCurrentStack",
"module": "db",
"tableId": tableId,
"module": "db",
"tableId": tableId,
})

// Get sqlite db connection
Expand All @@ -226,25 +226,25 @@ func ShowCurrentStack(tableId string) (stackUsers []User, err error) {
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": showCurrentStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error querying meeting table")
return nil, err
}
defer rows.Close()

// Parse database rows to User object slice
// Parse database rows to User object slice
for rows.Next() {
var stackUser User
err := rows.Scan(&stackUser.SpeakerPostition, &stackUser.SpeakerId, &stackUser.Name)
if err != nil {
log.WithFields(log.Fields{
"sqlQuery": showCurrentStackTableSQL,
"error": err.Error(),
"error": err.Error(),
}).Error("Error scanning query results for meeting table")
}
stackUsers = append(stackUsers, stackUser)
}

// Return current stack
return stackUsers, nil
}
}
2 changes: 1 addition & 1 deletion frontend/db/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import (
// ContextLogger declares top level context logger to use in package
var ContextLogger = log.WithFields(log.Fields{
"package": "db",
})
})
6 changes: 3 additions & 3 deletions go.mod → frontend/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module stack-web-app
module stack-web-app/frontend

go 1.15
go 1.16

require (
github.com/google/uuid v1.2.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/mattn/go-sqlite3 v1.14.6
github.com/mattn/go-sqlite3 v1.14.7
github.com/sirupsen/logrus v1.8.1
)
7 changes: 5 additions & 2 deletions go.sum → frontend/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
Expand All @@ -9,11 +10,13 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
12 changes: 6 additions & 6 deletions frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"net/http"
"os"

"stack-web-app/frontend/wshandler"
"stack-web-app/frontend/db"
"stack-web-app/frontend/wshandler"

"github.com/gorilla/handlers"
log "github.com/sirupsen/logrus"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

func main() {
Expand Down Expand Up @@ -54,7 +54,7 @@ func main() {
err := http.ListenAndServe(fmt.Sprintf(":%s", port), loggedRouter)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Fatal error with HTTP server")
"error": err.Error(),
}).Fatal("Fatal error with HTTP server")
}
}
}
Loading

0 comments on commit 2ebe8d2

Please sign in to comment.