Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Event System #271

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-bullseye
FROM golang:1.22-bullseye

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -

Expand Down
10 changes: 5 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
releases/
secrets/
config/
public/dist/build.js*
public/dist/
releases/
secrets/
config/
public/dist/build.js*
public/dist/
public/node_modules/
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Don't change line endings on .sh files
# Don't change line endings on .sh files
*.sh -crlf
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## next release
* Restructuring whole instance code to handle events.
* New feature: add timestamp on instance logs. [#259](https://github.com/assetto-corsa-web/accweb/issues/259)
* New feature: http callbacks over instance events.
* Fix incorrect best lap. [#272](https://github.com/assetto-corsa-web/accweb/issues/272)
* Fix missing driver. [#264](https://github.com/assetto-corsa-web/accweb/issues/264)


## 1.25.1
* makes majority of the entrylist fields optional [#278](https://github.com/assetto-corsa-web/accweb/pull/278)
* sorting nationalities, tracks and cars lists
Expand Down
108 changes: 55 additions & 53 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
FROM golang:1-bookworm AS builder

ARG VERSION=docker

ENV NODE_MAJOR=16

RUN apt-get update && apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y git build-essential nodejs="${NODE_MAJOR}.*" zip

WORKDIR /accweb_src

COPY . /accweb_src

# RUN rm public/dist/*
RUN sh build/build_release.sh ${VERSION}
RUN cd /accweb_src/releases && unzip accweb_${VERSION}.zip && mv accweb_${VERSION} /accweb

FROM alpine:3.18

LABEL description="Assetto Corsa Competizione Server Management Tool via Web Interface."

ARG VERSION=noversion

RUN apk add --no-cache gettext wine ca-certificates

RUN mkdir /accserver && mkdir /accweb

COPY --from=builder /accweb/accweb /accweb/accweb
COPY --from=builder /accweb_src/build/docker/* /accweb/

ENV ACCWEB_HOST=0.0.0.0:8080 \
ACCWEB_ENABLE_TLS=false \
ACCWEB_CERT_FILE=/sslcerts/certificate.crt \
ACCWEB_PRIV_FILE=/sslcerts/private.key \
ACCWEB_ADMIN_PASSWORD=weakadminpassword \
ACCWEB_MOD_PASSWORD=weakmodpassword \
ACCWEB_RO_PASSWORD=weakropassword \
ACCWEB_LOGLEVEL=info \
ACCWEB_CORS=*

VOLUME /accserver /accweb /sslcerts

WORKDIR /accweb

EXPOSE 8080

ENTRYPOINT [ "sh", "/accweb/docker-entrypoint.sh" ]

FROM golang:1.22-bookworm AS builder

ARG VERSION=docker

ENV NODE_MAJOR=16

RUN apt-get update && apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y git build-essential nodejs="${NODE_MAJOR}.*" zip

WORKDIR /accweb_src

COPY . /accweb_src

# RUN rm public/dist/*
RUN sh build/build_release.sh ${VERSION}
RUN cd /accweb_src/releases && unzip accweb_${VERSION}.zip && mv accweb_${VERSION} /accweb

FROM alpine:3.18

LABEL description="Assetto Corsa Competizione Server Management Tool via Web Interface."

ARG VERSION=noversion

RUN apk add --no-cache gettext wine ca-certificates

RUN mkdir /accserver && mkdir /accweb

COPY --from=builder /accweb/accweb /accweb/accweb
COPY --from=builder /accweb_src/build/docker/* /accweb/

ENV ACCWEB_HOST=0.0.0.0:8080 \
ACCWEB_ENABLE_TLS=false \
ACCWEB_CERT_FILE=/sslcerts/certificate.crt \
ACCWEB_PRIV_FILE=/sslcerts/private.key \
ACCWEB_ADMIN_PASSWORD=weakadminpassword \
ACCWEB_MOD_PASSWORD=weakmodpassword \
ACCWEB_RO_PASSWORD=weakropassword \
ACCWEB_LOGLEVEL=info \
ACCWEB_CORS=* \
ACCWEB_LOG_WITH_TIMESTAMP=true \
ACCWEB_CALLBACK_ENABLED=false

VOLUME /accserver /accweb /sslcerts

WORKDIR /accweb

EXPOSE 8080

ENTRYPOINT [ "sh", "/accweb/docker-entrypoint.sh" ]

CMD [ "start" ]
34 changes: 17 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
dev-setup:
cd public; npm install; npm run build
cp dev_config.yml config.yml

run-dev-backend:
go run cmd/main.go

run-dev-frontend:
cd public; npm run dev

swag:
${GOPATH}/bin/swag init -d cmd,internal -g ../internal/app/server.go

IMG ?= accweb/accweb
VERSION ?= dev
TAG ?= latest
docker-build:
dev-setup:
cd public; npm install; npm run build
cp dev_config.yml config.yml
run-dev-backend:
go run cmd/main.go
run-dev-frontend:
cd public; npm run dev
swag:
${GOPATH}/bin/swag init -d cmd,internal -g ../internal/app/server.go
IMG ?= accweb/accweb
VERSION ?= dev
TAG ?= latest
docker-build:
docker build . -t $(IMG):$(TAG) --progress plain --build-arg VERSION=$(VERSION) --build-arg COMMIT=`git rev-parse HEAD`
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ The successor of [acweb](https://github.com/assetto-corsa-web/acweb)! accweb let
* import/export server configuration files
* delete server configurations
* three different permissions: admin, mod and read only (using three different passwords)
* instance live view
* http callback for many instance events
* easy setup
* no database required
* simple configuration using environment variables
Expand Down
11 changes: 10 additions & 1 deletion build/docker/docker_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ loglevel: $ACCWEB_LOGLEVEL
cors:
origins: "$ACCWEB_CORS"
loglevel: $ACCWEB_LOGLEVEL


log:
with_timestamp: $ACCWEB_LOG_WITH_TIMESTAMP

callback:
enabled: $ACCWEB_CALLBACK_ENABLED
url: "$ACCWEB_CALLBACK_URL"
headers: $ACCWEB_CALLBACK_HEADERS
all_events: $ACCWEB_CALLBACK_ALL_EVENTS
events: $ACCWEB_CALLBACK_EVENTS
9 changes: 9 additions & 0 deletions build/sample_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ loglevel: info
cors:
origins: "*"
loglevel: info

log:
with_timestamp: true

# Event System configuration.
#
# More info: https://github.com/assetto-corsa-web/accweb/wiki/Event-System
callback:
enabled: false
71 changes: 43 additions & 28 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
package main

import (
"github.com/assetto-corsa-web/accweb/internal/app"
"github.com/assetto-corsa-web/accweb/internal/pkg/cfg"
"github.com/assetto-corsa-web/accweb/internal/pkg/helper"
"github.com/assetto-corsa-web/accweb/internal/pkg/server_manager"
"github.com/sirupsen/logrus"
)

const configFile = "config.yml"

func main() {
c := cfg.Load(configFile)

sM := server_manager.New(c.ConfigPath, c.ACC.ServerPath, c.ACC.ServerExe)

logrus.Info("accweb: checking for secrets...")
helper.GenerateTokenKeysIfNotPresent(c.Auth.PublicKeyPath, c.Auth.PrivateKeyPath)

logrus.Info("accweb: initializing...")
if err := sM.Bootstrap(); err != nil {
logrus.WithError(err).Fatal("failed to bootstrap accweb")
}

logrus.WithField("addr", c.Webserver.Host).Info("initializing web server")
app.StartServer(c, sM)
}
package main

import (
"os"
"os/signal"
"syscall"

"github.com/assetto-corsa-web/accweb/internal/app"
"github.com/assetto-corsa-web/accweb/internal/pkg/cfg"
"github.com/assetto-corsa-web/accweb/internal/pkg/helper"
"github.com/assetto-corsa-web/accweb/internal/pkg/server_manager"
"github.com/assetto-corsa-web/accweb/internal/pkg/server_manager/events"
"github.com/sirupsen/logrus"
)

const configFile = "config.yml"

func main() {
c := cfg.Load(configFile)

sM := server_manager.New(c)

logrus.Info("accweb: checking for secrets...")
helper.GenerateTokenKeysIfNotPresent(c.Auth.PublicKeyPath, c.Auth.PrivateKeyPath)

logrus.Info("accweb: initializing...")

events.InitializeAll(sM)

if err := sM.Bootstrap(); err != nil {
logrus.WithError(err).Fatal("failed to bootstrap accweb")
}

logrus.WithField("addr", c.Webserver.Host).Info("initializing web server")
go app.StartServer(c, sM)

signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-signalChannel

logrus.Info("Gracefully terminating...")
sM.StopAll()
}
30 changes: 30 additions & 0 deletions dev_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,33 @@ loglevel: debug
cors:
origins: "*"
loglevel: info

log:
with_timestamp: true

# Event System configuration.
#
# More info: https://github.com/assetto-corsa-web/accweb/wiki/Event-System
callback:
enabled: false
clients:
# simple example (enabled, no http headers and all events)
- url: "http://localhost:3000/callback1"
# complete example (enabled, with custom headers and few events)
- url: "http://localhost:3000/callback2"
enabled: true
headers:
"some-header": "aabbcc"
events:
- "instance_started"
- "instance_stopped"
# - "instance_live_new_driver"
# - "instance_live_remove_connection"
# - "instance_live_new_lap"
# - "instance_live_session_phase_changed"
# - "instance_live_new_damage_zone"
# - "instance_live_reseting_race_weekend"
# - "instance_live_session_changed"
# disabled client
- url: "http://localhost:3000/callback3"
enabled: false
31 changes: 31 additions & 0 deletions internal/pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cfg

import (
"os"
"path"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -26,6 +27,12 @@ type Config struct {
CORS CORS `yaml:"cors"`
Auth Auth `yaml:"auth"`
ACC ACC `yaml:"acc"`
Log Log `yaml:"log"`
Callback Callback `yaml:"callback"`
}

func (c Config) AccServerFullPath() string {
return path.Join(c.ACC.ServerPath, c.ACC.ServerExe)
}

type Webserver struct {
Expand Down Expand Up @@ -54,6 +61,30 @@ type ACC struct {
ServerExe string `yaml:"server_exe"`
}

type Log struct {
WithTimestamp bool `yaml:"with_timestamp"`
}

type CallbackOld struct {
Enabled bool `yaml:"enabled"`
Urls []string `yaml:"urls"`
Headers map[string]string `yaml:"headers"`
AllEvents bool `yaml:"all_events"`
Events []string `yaml:"events"`
}

type Callback struct {
Enabled bool `yaml:"enabled"`
Clients []CallbackClient `yaml:"clients"`
}

type CallbackClient struct {
Enabled *bool `yaml:"enabled"`
Url string `yaml:"url"`
Headers map[string]string `yaml:"headers"`
Events []string `yaml:"events"`
}

// Load loads the application config from config.yml.
func Load(file string) *Config {
data, err := os.ReadFile(file)
Expand Down
Loading