diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..cee7328 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,78 @@ +name: Build Docker Containers + +on: + push: + branches: + - main + paths-ignore: + - "README.md" + - "LICENSE" + - ".gitignore" + workflow_dispatch: + +jobs: + + build-alpine: + permissions: write-all + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Alpine Dockerfile + id: docker_build + uses: docker/build-push-action@v3.2.0 + with: + platforms: linux/arm64,linux/armhf,linux/386,linux/amd64 + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:alpine + pull: false + context: . + file: Dockerfile + + build-debian: + permissions: write-all + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Debian Dockerfile + id: docker_build + uses: docker/build-push-action@v3.2.0 + with: + platforms: linux/arm64,linux/armhf,linux/386,linux/amd64 + push: true + tags: | + ghcr.io/${{ github.repository }}:debian + pull: false + context: . + file: Debian_Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cee7328..73687a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,78 +1,28 @@ -name: Build Docker Containers +name: goreleaser on: push: - branches: - - main - paths-ignore: - - "README.md" - - "LICENSE" - - ".gitignore" - workflow_dispatch: + tags: + - "*" -jobs: +permissions: + contents: write - build-alpine: - permissions: write-all +jobs: + goreleaser: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and Push Alpine Dockerfile - id: docker_build - uses: docker/build-push-action@v3.2.0 + - uses: actions/checkout@v3 with: - platforms: linux/arm64,linux/armhf,linux/386,linux/amd64 - push: true - tags: | - ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:alpine - pull: false - context: . - file: Dockerfile - - build-debian: - permissions: write-all - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Container Registry - uses: docker/login-action@v2 + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v4 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and Push Debian Dockerfile - id: docker_build - uses: docker/build-push-action@v3.2.0 + go-version: stable + - uses: goreleaser/goreleaser-action@v4 with: - platforms: linux/arm64,linux/armhf,linux/386,linux/amd64 - push: true - tags: | - ghcr.io/${{ github.repository }}:debian - pull: false - context: . - file: Debian_Dockerfile + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..bfcca79 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,51 @@ +--- +before: + hooks: + - go mod tidy -compat=1.20 + - go mod vendor + +release: + prerelease: auto + +builds: + - id: wolweb + mod_timestamp: "{{ .CommitTimestamp }}" + env: + - CGO_ENABLED=0 + targets: + - darwin_amd64 + - darwin_arm64 + - freebsd_amd64 + - linux_386 + - linux_amd64 + - linux_arm64 + - linux_arm_5 + - linux_arm_6 + - linux_arm_7 + flags: + - -mod=readonly + ldflags: + - -s -w -X main.Version={{.Version}} + +archives: + - id: golang-cross + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' + format: binary + +source: + enabled: true + name_template: "{{ .ProjectName }}_{{ .Version }}" + format: tar.gz + files: + - "vendor/" + +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/main.go b/main.go index 8409845..1fe36e0 100644 --- a/main.go +++ b/main.go @@ -15,21 +15,23 @@ import ( "github.com/ilyakaznacheev/cleanenv" ) +var Version = "dev" + // Global variables -var appConfig AppConfig -var appData AppData +var ( + appConfig AppConfig + appData AppData +) func main() { - + log.Printf("Starting WakeOnLan Webserver version %s", Version) setWorkingDir() loadConfig() loadData() setupWebServer() - } func setWorkingDir() { - thisApp, err := os.Executable() if err != nil { log.Fatalf("Error determining the directory. \"%s\"", err) @@ -37,21 +39,17 @@ func setWorkingDir() { appPath := filepath.Dir(thisApp) os.Chdir(appPath) log.Printf("Set working directory: %s", appPath) - } func loadConfig() { - err := cleanenv.ReadConfig("config.json", &appConfig) if err != nil { log.Fatalf("Error loading config.json file. \"%s\"", err) } log.Printf("Application configuratrion loaded from config.json") - } func setupWebServer() { - // Init HTTP Router - mux router := mux.NewRouter() @@ -95,7 +93,6 @@ func setupWebServer() { } log.Fatal(srv.ListenAndServe()) - } func CacheControlWrapper(h http.Handler) http.Handler {