Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 27, 2024
1 parent fd7689d commit d88ddd8
Show file tree
Hide file tree
Showing 22 changed files with 1,608 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
cmd = "make -s init"
bin = "bin"

34 changes: 34 additions & 0 deletions .github/workflows/go-bin-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go binary release

on:
release:
types: [created, edited]

permissions:
contents: write
packages: write

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: ["linux", "darwin", "windows"]
goarch: ["amd64", "386", "arm64"]
exclude:
- goarch: "386"
goos: "darwin"
- goarch: "arm64"
goos: "windows"
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
binary_name: "wgg"
goversion: "1.23"
extra_files: LICENSE README.md CONTRIBUTING.md
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
ldflags: "-X main.Version=${{ github.ref_name }} -X main.Commit=${{ github.sha }}"
30 changes: 30 additions & 0 deletions .github/workflows/go-test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go build and test

on:
push:
branches: ["main"]
paths:
- "**.go"
- "go.*"
- "Makefile"

permissions:
contents: write
packages: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"

- name: Test
run: make test

- name: Build
run: make build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ go.work
go.work.sum
bin
tmp
config
config
.env
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing

We welcome contributions from the community to help improve this project.
Your input is valuable to us.

You can contribute to the project in the following ways:

### **Create Issues**
Feel free to create issues for:
- feature requests,
- bug fixes,
- documentation improvements,
- test cases,
- general questions,
- or any recommendations you may have.
### **Merge Requests**
Please avoid multiple different changes in one merge request.
1. **Fork** the repository,
2. **commit and push** your changes,
3. and submit your **merge request**:
- with a clear explanation of the changes you've made,
- and a note with your thoughts about your tests.

There are many reasons for submitting a merge request:
- Fixing bugs,
- implement new features,
- improve documentation,
- and adding tests.

## Rules for Contributions

To ensure a smooth contribution process, please follow the rules below:

- **License Awareness**: Be aware of and check the LICENSE file before contributing to understand the project's licence terms.
- **Respect the Licence Terms**: Ensure that your contributions comply with the project's license terms.
- **Avoid Plagiarism**: Do not plagiarise code or content from other sources. All contributions should be original work or properly attributed.
- **Platform Rules** Also be sure to follow the rules of the provider and the platform.

## Thank you
A big thank you, for considering a contribution.
If anything is unclear, please contact us via a issue with your question.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### BASE
FROM golang AS base

EXPOSE 8080
WORKDIR /app

COPY go.mod* go.sum* ./
RUN go mod tidy

### LOCAL
FROM base AS local

RUN go install github.com/air-verse/air@v1

ENTRYPOINT air

### BASE DEPLOY
FROM base AS base-deploy
COPY . .
RUN make mainbuild

### DEPLOY
FROM ubuntu:24.04 AS deploy

RUN useradd -m appuser --uid 10000
USER 10000

COPY --from=base-deploy --chown=10000 /app/bin /usr/local/bin/appbin

CMD ["appbin"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Majo Richter (NobleMajo)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 changes: 113 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
DISPLAY_NAME := DeployIT
SHORT_NAME := dit
VERSION := 1.0.0

COMMIT := $(shell git rev-parse --short HEAD)
BUILD_ARGS := "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.DisplayName=$(DISPLAY_NAME) -X main.ShortName=$(SHORT_NAME)"
PORT ?= 8080

-include .env
export

## info: prints a project info message
.PHONY: info
info:
@echo "$(DISPLAY_NAME) version $(VERSION), build $(COMMIT)"

## run: uses go to start the main.go
.PHONY: run
run:
@go run main.go

## build: uses go to build the app with build args
.PHONY: build
build:
@touch .env
go build \
-ldflags=$(BUILD_ARGS) \
-o bin
chmod +x bin

## clean: cleans up the tmp, build and docker cache
.PHONY: clean
clean:
@rm -f bin
@rm -fr ./tmp
@if command -v go 2>&1 >/dev/null; then \
echo "cleanup go..."; \
go clean; \
go clean -cache -fuzzcache; \
fi
@if command -v docker 2>&1 >/dev/null; then \
echo "cleanup docker..."; \
CACHE_DIR="" PORT="" docker compose down --remove-orphans --rmi all; \
docker image prune -f; \
fi
@echo "cleanup done!"
@echo "WARNING: the .env file still exists!"


## update: updates dependencies
.PHONY: update
update:
go get -t -u ./...

## test: runs all tests without coverage
.PHONY: test
test:
go test ./...

## init: prepares ands builds
.PHONY: init
init:
@touch .env
@echo "update deps..."
@go mod tidy
@echo "testing..."
@make -s test
@echo "building..."
@make -s build

## air: starts the go bin in air watch mode
.PHONY: air
air:
@go install github.com/air-verse/air@v1
@air

## dev: starts a dev docker container
.PHONY: dev
dev:
@touch .env
$(eval CACHE_DIR = .tmp/.cache/go-build)
@if [ -d ~/.cache/go-build ]; then \
$(eval CACHE_DIR = ~/.cache/go-build) \
echo "Use users go-build cache dir."; \
else \
mkdir -p $(CACHE_DIR); \
echo "Use local go-build cache dir."; \
fi

@docker rm -f $(SHORT_NAME)-local-dev > /dev/null 2>&1

PORT=${PORT} \
CACHE_DIR=${CACHE_DIR} \
docker compose run --build --rm -it --name $(SHORT_NAME)-local-dev -P local

## exec: starts a bash in a dev container
.PHONY: exec
exec:
@touch .env
$(eval CACHE_DIR = .tmp/.cache/go-build)
@if [ -d ~/.cache/go-build ]; then \
$(eval CACHE_DIR = ~/.cache/go-build) \
echo "Use users go-build cache dir."; \
else \
mkdir -p $(CACHE_DIR); \
echo "Use local go-build cache dir."; \
fi

@docker rm -f $(SHORT_NAME)-local-bash > /dev/null 2>&1

PORT=${PORT} \
CACHE_DIR=${CACHE_DIR} \
docker compose run --build --rm -it --name $(SHORT_NAME)-local-bash --entrypoint bash -P local
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# WireGuardGenerator
![CI/CD](https://github.com/CoreUnit-NET/wgg/actions/workflows/go-bin-release.yml/badge.svg)
![CI/CD](https://github.com/CoreUnit-NET/wgg/actions/workflows/go-test-build.yml/badge.svg)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![](https://img.shields.io/badge/dynamic/json?color=green&label=watchers&query=watchers&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fnoblemajo%2Fwgg)
![](https://img.shields.io/badge/dynamic/json?color=yellow&label=stars&query=stargazers_count&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fnoblemajo%2Fwgg)
![](https://img.shields.io/badge/dynamic/json?color=navy&label=forks&query=forks&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fnoblemajo%2Fwgg)

Generates basic p2p node and client configs with private and public keys.
You need to define env vars.

Also loads .env files.

Env vars:
```bash
WGG_SUBNET=10.20.30.0/24
WGG_NODE1=<node1-ip>:55333
WGG_NODE2=<node2-ip>:55333
WGG_NODE3=<node3-ip>:55333
WGG_CLIENT_COUNT=5
WGG_OUT_DIR=wgout
```

# Table of Contents
- [WireGuardGenerator](#wireguardgenerator)
- [Table of Contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [Install via go](#install-via-go)
- [Install via wget](#install-via-wget)
- [Build](#build)
- [Install go](#install-go)
- [Contributing](#contributing)
- [License](#license)
- [Disclaimer](#disclaimer)

# Getting Started

## Requirements
None windows system with `go` or `wget & tar` installed.

## Install via go
###### *For this section go is required, check out the [install go guide](#install-go).*

```sh
go install https://github.com/CoreUnit-NET/wgg
```

## Install via wget
```sh
BIN_DIR="/usr/local/bin"
WGG_VERSION="1.3.3"

rm -rf $BIN_DIR/wgg
wget https://github.com/CoreUnit-NET/wgg/releases/download/v$WGG_VERSION/wgg-v$WGG_VERSION-linux-amd64.tar.gz -O /tmp/wgg.tar.gz
tar -xzvf /tmp/wgg.tar.gz -C $BIN_DIR/ wgg
rm /tmp/wgg.tar.gz
```

## Build
###### *For this section go is required, check out the [install go guide](#install-go).*

Clone the repo:
```sh
git clone https://github.com/CoreUnit-NET/wgg.git
cd wgg
```

Build the wgg binary from source code:
```sh
make build
./wgg
```

## Install go
The required go version for this project is in the `go.mod` file.

To install and update go, I can recommend the following repo:
```sh
git clone [email protected]:udhos/update-golang.git golang-updater
cd golang-updater
sudo ./update-golang.sh
```

# Contributing
Contributions to this project are welcome!
Interested users can refer to the guidelines provided in the [CONTRIBUTING.md](CONTRIBUTING.md) file to contribute to the project and help improve its functionality and features.

# License
This project is licensed under the [MIT license](LICENSE), providing users with flexibility and freedom to use and modify the software according to their needs.

# Disclaimer
This project is provided without warranties.
Users are advised to review the accompanying license for more information on the terms of use and limitations of liability.
Loading

0 comments on commit d88ddd8

Please sign in to comment.