diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d199e3e..ef38b90f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,7 +55,7 @@ jobs: fi working_directory: ~/repo docker: - - image: cimg/go:1.20-node + - image: cimg/go:1.21-node workflows: build-and-release: diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index f2719998..879ab394 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -7,7 +7,7 @@ name: Docker on: push: - branches: [ master ] + branches: [ master, stable ] # Publish vX.X.X tags as releases. tags: [ 'v*.*.*' ] @@ -24,13 +24,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Get Version shell: bash @@ -41,27 +41,28 @@ jobs: - name: Log in to Docker Hub if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: - images: h44z/wg-portal + images: wgportal/wg-portal flavor: | latest=true prefix= suffix= tags: | type=ref,event=branch - type=ref,event=tag type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern=v{{major}} - name: Build and push Docker image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' }} @@ -81,13 +82,13 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Get Version shell: bash @@ -100,7 +101,7 @@ jobs: # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -110,7 +111,7 @@ jobs: # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} flavor: | @@ -119,13 +120,14 @@ jobs: suffix= tags: | type=ref,event=branch - type=ref,event=tag type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern=v{{major}} # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' }} diff --git a/Dockerfile b/Dockerfile index 29256984..2ef66ad1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ######- # Start from the latest golang base image as builder image (only used to compile the code) ######- -FROM golang:1.20 as builder +FROM golang:1.21 as builder ARG BUILD_IDENTIFIER ENV ENV_BUILD_IDENTIFIER=$BUILD_IDENTIFIER @@ -46,5 +46,11 @@ COPY --from=builder /build/dist/wg-portal /app/wg-portal # Set the Current Working Directory inside the container WORKDIR /app +# by default, the web-portal is reachable on port 8888 +EXPOSE 8888/tcp + +# the database and config file can be mounted from the host +VOLUME [ "/app/data", "/app/config" ] + # Command to run the executable -CMD [ "/app/wg-portal" ] \ No newline at end of file +ENTRYPOINT [ "/app/wg-portal" ] \ No newline at end of file diff --git a/README.md b/README.md index 3bde83b8..713fb311 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WireGuard Portal (V2 - alpha testing) +# WireGuard Portal (v2 - testing) [![Build Status](https://travis-ci.com/h44z/wg-portal.svg?token=q4pSqaqT58Jzpxdx62xk&branch=master)](https://travis-ci.com/h44z/wg-portal) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT) @@ -6,10 +6,13 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/h44z/wg-portal)](https://goreportcard.com/report/github.com/h44z/wg-portal) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/h44z/wg-portal) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/h44z/wg-portal) -[![Docker Pulls](https://img.shields.io/docker/pulls/h44z/wg-portal.svg)](https://hub.docker.com/r/h44z/wg-portal/) +[![Docker Pulls](https://img.shields.io/docker/pulls/h44z/wg-portal.svg)](https://hub.docker.com/r/wgportal/wg-portal/) > :warning: **IMPORTANT** Version 2 is currently under development and may contain bugs. It is currently not advised to use this version -in production. Use version [1.0.18](https://github.com/h44z/wg-portal/releases) instead. +in production. Use version [v1](https://github.com/h44z/wg-portal/tree/stable) instead. + +Since the project was accepted by the Docker-Sponsored Open Source Program, the Docker image location has moved to: https://hub.docker.com/r/wgportal/wg-portal. +Please update the Docker image from **h44z/wg-portal** to **wgportal/wg-portal**. A simple, web based configuration portal for [WireGuard](https://wireguard.com). The portal uses the WireGuard [wgctrl](https://github.com/WireGuard/wgctrl-go) library to manage existing VPN @@ -41,10 +44,12 @@ The configuration portal supports using a database (SQLite, MySQL, MsSQL or Post ## Configuration You can configure WireGuard Portal using a yaml configuration file. -The filepath of the yaml configuration file defaults to **config.yml** in the working directory of the executable. +The filepath of the yaml configuration file defaults to **config/config.yml** in the working directory of the executable. It is possible to override the configuration filepath using the environment variable **WG_PORTAL_CONFIG**. For example: `WG_PORTAL_CONFIG=/home/test/config.yml ./wg-portal-amd64`. +By default, WireGuard Portal uses a SQLite database. The database is stored in **data/sqlite.db** in the working directory of the executable. + ### Configuration Options The following configuration options are available: @@ -128,7 +133,7 @@ The following configuration options are available: | debug | database | false | Debug database statements (log each statement). | | slow_query_threshold | database | | A threshold for slow database queries. If the threshold is exceeded, a warning message will be logged. | | type | database | sqlite | The database type. Allowed values: sqlite, mssql, mysql or postgres. | -| dsn | database | sqlite.db | The database DSN. For example: user:pass@tcp(1.2.3.4:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local | +| dsn | database | data/sqlite.db | The database DSN. For example: user:pass@tcp(1.2.3.4:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local | | request_logging | web | false | Log all HTTP requests. | | external_url | web | http://localhost:8888 | The URL where a client can access WireGuard Portal. | | listening_address | web | :8888 | The listening port of the web server. | diff --git a/docker-compose.yml b/docker-compose.yml index 8b640a63..a903d9bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.6' services: wg-portal: - image: h44z/wg-portal:2.0.0-alpha1 + image: h44z/wg-portal:v2 container_name: wg-portal restart: unless-stopped logging: @@ -15,5 +15,7 @@ services: volumes: - /etc/wireguard:/etc/wireguard - ./data:/app/data - environment: - - EXTERNAL_URL=http://localhost:8888 + - ./config:/app/config +# restart: no +# command: ["-migrateFrom=/app/data/wg_portal.db"] + diff --git a/go.mod b/go.mod index 7786e4e0..df0bf1e9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/h44z/wg-portal -go 1.20 +go 1.21 require ( github.com/coreos/go-oidc/v3 v3.6.0 diff --git a/hooks/build b/hooks/build deleted file mode 100755 index 622fc06d..00000000 --- a/hooks/build +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# File needs to be called /hooks/build relative to the Dockerfile. -# Some environment variables are injected into the build hook, see: https://docs.docker.com/docker-hub/builds/advanced/. - -GIT_SHORT_HASH=$(echo $SOURCE_COMMIT | cut -c1-7) -echo "Build hook running for git hash $GIT_SHORT_HASH" -docker build --build-arg BUILD_IDENTIFIER=$DOCKER_TAG \ - --build-arg BUILD_VERSION=$GIT_SHORT_HASH \ - -t $IMAGE_NAME . \ No newline at end of file diff --git a/internal/config/config.go b/internal/config/config.go index 1beae780..1feb6903 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -87,7 +87,7 @@ func defaultConfig() *Config { cfg.Database = DatabaseConfig{ Type: "sqlite", - DSN: "sqlite.db", + DSN: "data/sqlite.db", } cfg.Web = WebConfig{ @@ -140,7 +140,7 @@ func GetConfig() (*Config, error) { // override config values from YAML file - cfgFileName := "config.yml" + cfgFileName := "config/config.yml" if envCfgFileName := os.Getenv("WG_PORTAL_CONFIG"); envCfgFileName != "" { cfgFileName = envCfgFileName }