diff --git a/.gitignore b/.gitignore index 4a1b32bf..dbd10f74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,63 @@ +### Default ignore for this project ### config.yaml data/ ./wg-access-server + +### Code ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +### Go Patch ### +/vendor/ +/Godeps/ + +### react ### +.DS_* +*.log +logs +**/*.backup.* +**/*.back.* + +### website react app ### + +# dependencies +website/node_modules +website/.pnp +website/.pnp.js + +# testing +website/coverage + +# production +website/build + +# misc +website/.DS_Store +website/.env.local +website/.env.development.local +website/.env.test.local +website/.env.production.local + +website/npm-debug.log* +website/yarn-debug.log* +website/yarn-error.log* +website/yarn.lock + + diff --git a/Dockerfile b/Dockerfile index ae00f254..ec1f3728 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,56 @@ +### Build stage for the website frontend FROM node:10 as website + WORKDIR /code + COPY ./website/package.json ./ COPY ./website/package-lock.json ./ + +# install dependency RUN npm install + COPY ./website/ ./ + RUN npm run build +### Build stage for the website backend server FROM golang:1.13.8 as server + WORKDIR /code + +# Environment variable ENV GOOS=linux ENV GARCH=amd64 ENV CGO_ENABLED=0 ENV GO111MODULE=on + COPY ./go.mod ./ COPY ./go.sum ./ + RUN go mod download + COPY ./proto/ ./proto/ COPY ./main.go ./main.go COPY ./internal/ ./internal + RUN go build -o server +### Server FROM alpine:3.10 -RUN apk add iptables -RUN apk add wireguard-tools + +# Environment variable ENV CONFIG="/config.yaml" ENV STORAGE_DIRECTORY="/data" + +RUN apk add iptables +RUN apk add wireguard-tools +RUN apk add curl + +# Copy the final build for the frontend and backend COPY --from=server /code/server /server COPY --from=website /code/build /website/build + +HEALTHCHECK --interval=5m --timeout=3s CMD curl -f http://localhost:8000/ || exit 1 + +# Command to start the server CMD /server diff --git a/README.md b/README.md index 0038f18b..a9fc5b6b 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,12 @@ network as well. Here's a quick command to run the server to try it out. If you open your browser using your LAN ip address you can even connect your -phone to try it out: for example, i'll open my browser at http://192.168.0.15:8000 -using my laptop's LAN IP address. +phone to try it out: for example, i'll open my browser at http://192.168.0.XX:8000 +using the local LAN IP address. -``` +You can connect to the web server on the local machine browser at http://localhost:8000 + +```bash docker run \ -it \ --rm \ @@ -48,11 +50,21 @@ docker run \ place1/wg-access-server ``` +## Running with Docker-Compose + +You modify the docker-compose.yml file for you need then run this following command. + +```bash +docker-compose up -d +``` + +You can connect to the web server on the local machine browser at http://localhost:8000 + ## Configuration You can configure the server using a yaml configuration file. Just mount the file into the container like this: -``` +```bash docker run \ ... \ -v $(pwd)/config.yaml:/config.yaml \ @@ -205,8 +217,8 @@ The software is made up a Golang Server and React App. Here's how I develop locally: -2. run `cd website && npm install && npm start` to get the frontend running on `:3000` -3. run `sudo go run ./main.go` to get the server running on `:8000` +1. run `cd website && npm install && npm start` to get the frontend running on `:3000` +2. run `sudo go run ./main.go` to get the server running on `:8000` Here are some notes about the development configuration: diff --git a/codegen.sh b/codegen.sh index b70cc497..46e35796 100755 --- a/codegen.sh +++ b/codegen.sh @@ -1,9 +1,8 @@ #!/bin/bash set -e -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -OUT_DIR="$DIR/proto/proto" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +OUT_DIR="$SCRIPT_DIR/proto/proto" mkdir -p "$OUT_DIR" || true @@ -12,4 +11,5 @@ protoc \ proto/*.proto \ --go_out="plugins=grpc:$OUT_DIR" -cd website && npm run codegen +cd website || exit +npm run codegen diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..2d0415af --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.7" +services: + wg-access-server: + # to build the docker image from the source + # build: + # dockerfile: Dockerfile + # context: . + image: place1/wg-access-server + container_name: wg-access-server + cap_add: + - NET_ADMIN + volumes: + - "wg-access-server-data:/data" + # - "config.yaml/config.yaml" # if you have a custom confg file + ports: + - "8000:8000/tcp" + - "51820:51820/udp" + devices: + - "/dev/net/tun:/dev/net/tun" + +# shared volumes with the host +volumes: + wg-access-server-data: + driver: local diff --git a/docs/index.yaml b/docs/index.yaml index 0437d42c..39434227 100644 --- a/docs/index.yaml +++ b/docs/index.yaml @@ -1,13 +1,13 @@ apiVersion: v1 entries: wg-access-server: - - apiVersion: v2 - appVersion: 0.0.9 - created: "2020-03-08T15:27:38.5587792+11:00" - description: A Wireguard VPN Access Server - digest: e8d795290f577d5d5678619dac42e1a667407aa7128a682da30f26db9f383a1c - name: wg-access-server - urls: - - https://place1.github.io/wg-access-server/charts/wg-access-server-0.0.9.tgz - version: 0.0.9 + - apiVersion: v2 + appVersion: 0.0.9 + created: "2020-03-08T15:27:38.5587792+11:00" + description: A Wireguard VPN Access Server + digest: e8d795290f577d5d5678619dac42e1a667407aa7128a682da30f26db9f383a1c + name: wg-access-server + urls: + - https://place1.github.io/wg-access-server/charts/wg-access-server-0.0.9.tgz + version: 0.0.9 generated: "2020-03-08T15:27:38.5581672+11:00" diff --git a/publish.py b/publish.py index e382f556..6130c945 100755 --- a/publish.py +++ b/publish.py @@ -10,11 +10,12 @@ .read() \ .decode('utf-8') tags = json.loads(r).get('results', []) -print('current docker tags:', sorted([t.get('name') for t in tags], reverse=True)) +print('current docker tags:', sorted( + [t.get('name') for t in tags], reverse=True)) # tag the new image version = input('Version: ') -docker_tag=f"place1/wg-access-server:{version}" +docker_tag = f"place1/wg-access-server:{version}" # subprocess.run(['docker', 'build', '-t', docker_tag, '.']) # update the helm chart and quickstart manifest @@ -26,9 +27,12 @@ yaml.dump(chart, f, default_flow_style=False) f.truncate() with open('deploy/k8s/quickstart.yaml', 'w') as f: - subprocess.run(['helm', 'template', '--name-template', 'quickstart', 'deploy/helm/wg-access-server/'], stdout=f) -subprocess.run(['helm', 'package', 'deploy/helm/wg-access-server/', '--destination', 'docs/charts/']) -subprocess.run(['helm', 'repo', 'index', 'docs/', '--url', 'https://place1.github.io/wg-access-server']) + subprocess.run(['helm', 'template', '--name-template', + 'quickstart', 'deploy/helm/wg-access-server/'], stdout=f) +subprocess.run(['helm', 'package', 'deploy/helm/wg-access-server/', + '--destination', 'docs/charts/']) +subprocess.run(['helm', 'repo', 'index', 'docs/', '--url', + 'https://place1.github.io/wg-access-server']) # commit changes subprocess.run(['git', 'add', 'deploy']) diff --git a/website/.gitignore b/website/.gitignore deleted file mode 100644 index 7d3cec2e..00000000 --- a/website/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js - -# testing -/coverage - -# production -/build - -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* -yarn.lock diff --git a/website/README.md b/website/README.md index 2fa78e71..10a98f24 100644 --- a/website/README.md +++ b/website/README.md @@ -1,33 +1,37 @@ +# React App This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). ## Available Scripts -In the project directory, you can run: +### `yarn start` or `npm run start` -### `yarn start` +Runs the app in the development mode. -Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. -The page will reload if you make edits.
+The page will reload if you make edits. + You will also see any lint errors in the console. -### `yarn test` +### `yarn test` or `npm run test` + +Launches the test runner in the interactive watch mode. -Launches the test runner in the interactive watch mode.
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. -### `yarn build` +### `yarn build` or `npm run build` + +Builds the app for production to the `build` folder. -Builds the app for production to the `build` folder.
It correctly bundles React in production mode and optimizes the build for the best performance. -The build is minified and the filenames include the hashes.
+The build is minified and the filenames include the hashes. + Your app is ready to be deployed! See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -### `yarn eject` +### `yarn eject` or `npm run eject` **Note: this is a one-way operation. Once you `eject`, you can’t go back!** diff --git a/website/package-lock.json b/website/package-lock.json index b501af27..a407c1a1 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -1059,9 +1059,9 @@ "integrity": "sha512-1dVNHT76Uu5N3eJNTYcvxee+jzX4Z9lfciqRRHCU27ihbUcYi+iSc2iml5Ke1LXe1SyJCLA0+14Jh4tXJgOppA==" }, "@hapi/hoek": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.5.0.tgz", - "integrity": "sha512-7XYT10CZfPsH7j9F1Jmg1+d0ezOux2oM2GfArAzLwWe4mE2Dr3hVjsAL6+TFY49RRJlCdJDMw3nJsLFroTc8Kw==" + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.5.1.tgz", + "integrity": "sha512-yN7kbciD87WzLGc5539Tn0sApjyiGHAJgKvG9W8C7O+6c7qmoQMfVs0W4bX17eqz6C78QJqqFrtgdK5EWf6Qow==" }, "@hapi/joi": { "version": "15.1.1", @@ -1889,9 +1889,9 @@ } }, "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==" + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==" }, "acorn-globals": { "version": "4.3.4", @@ -1903,9 +1903,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", - "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==" + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==" } } }, @@ -7436,9 +7436,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", - "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==" + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==" }, "jsdom": { "version": "14.1.0", @@ -13701,9 +13701,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", - "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==" + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==" }, "cacache": { "version": "12.0.3", diff --git a/website/public/favicon.ico b/website/public/favicon.ico index c2c86b85..6ed05e82 100644 Binary files a/website/public/favicon.ico and b/website/public/favicon.ico differ diff --git a/website/public/index.html b/website/public/index.html index e8fe1b31..19f4f21c 100644 --- a/website/public/index.html +++ b/website/public/index.html @@ -5,11 +5,8 @@ - - + + - React App + Wireguard Access Portal diff --git a/website/public/logo-192.png b/website/public/logo-192.png new file mode 100644 index 00000000..84459d1c Binary files /dev/null and b/website/public/logo-192.png differ diff --git a/website/public/logo-310.png b/website/public/logo-310.png new file mode 100644 index 00000000..ce15f3b2 Binary files /dev/null and b/website/public/logo-310.png differ diff --git a/website/public/logo192.png b/website/public/logo192.png deleted file mode 100644 index fa313abf..00000000 Binary files a/website/public/logo192.png and /dev/null differ diff --git a/website/public/logo512.png b/website/public/logo512.png deleted file mode 100644 index bd5d4b5e..00000000 Binary files a/website/public/logo512.png and /dev/null differ diff --git a/website/public/manifest.json b/website/public/manifest.json index 080d6c77..50479341 100644 --- a/website/public/manifest.json +++ b/website/public/manifest.json @@ -8,14 +8,14 @@ "type": "image/x-icon" }, { - "src": "logo192.png", + "src": "logo-192.png", "type": "image/png", "sizes": "192x192" }, { - "src": "logo512.png", + "src": "logo-310.png", "type": "image/png", - "sizes": "512x512" + "sizes": "301x310" } ], "start_url": ".", diff --git a/website/src/Cookies.ts b/website/src/Cookies.ts index 6d2f882e..1f2d7cca 100644 --- a/website/src/Cookies.ts +++ b/website/src/Cookies.ts @@ -5,15 +5,15 @@ export function getCookie(name: string): string | undefined { const prefix = name + '='; let begin = dc.indexOf('; ' + prefix); let end = undefined; - if (begin == -1) { + if (begin === -1) { begin = dc.indexOf(prefix); - if (begin != 0) { + if (begin !== 0) { return undefined; } } else { begin += 2; end = document.cookie.indexOf(';', begin); - if (end == -1) { + if (end === -1) { end = dc.length; } } diff --git a/website/tsconfig.json b/website/tsconfig.json index f2850b71..af10394b 100644 --- a/website/tsconfig.json +++ b/website/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, @@ -19,7 +15,5 @@ "noEmit": true, "jsx": "react" }, - "include": [ - "src" - ] + "include": ["src"] }