Skip to content

Commit

Permalink
Added GH workflow, readme, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Mar 25, 2024
1 parent db5372c commit a22a3c8
Show file tree
Hide file tree
Showing 20 changed files with 844 additions and 185 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build

'on':
'push':
'tags':
- 'v*'
'branches':
- '*'
'pull_request':

jobs:
tests:
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
strategy:
matrix:
os:
- windows-latest
- macos-latest
- ubuntu-latest

steps:
- uses: actions/checkout@master

- uses: actions/setup-go@v3
with:
go-version: 1.x

- name: Run tests
run: |-
go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage
uses: codecov/codecov-action@v3
if: "success() && matrix.os == 'ubuntu-latest'"
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt

build:
needs:
- tests
runs-on: ubuntu-latest
env:
GO111MODULE: "on"
steps:
- uses: actions/checkout@master

- uses: actions/setup-go@v3
with:
go-version: 1.x

- name: Prepare environment
run: |-
RELEASE_VERSION="${GITHUB_REF##*/}"
if [[ "${RELEASE_VERSION}" != v* ]]; then RELEASE_VERSION='dev'; fi
echo "RELEASE_VERSION=\"${RELEASE_VERSION}\"" >> $GITHUB_ENV
# Win
- run: GOOS=windows GOARCH=386 VERSION=${RELEASE_VERSION} make release
- run: GOOS=windows GOARCH=amd64 VERSION=${RELEASE_VERSION} make release

# MacOS
- run: GOOS=darwin GOARCH=amd64 VERSION=${RELEASE_VERSION} make release

# MacOS ARM
- run: GOOS=darwin GOARCH=arm64 VERSION=${RELEASE_VERSION} make release

# Linux X86
- run: GOOS=linux GOARCH=386 VERSION=${RELEASE_VERSION} make release
- run: GOOS=linux GOARCH=amd64 VERSION=${RELEASE_VERSION} make release

# Linux ARM
- run: GOOS=linux GOARCH=arm GOARM=6 VERSION=${RELEASE_VERSION} make release
- run: GOOS=linux GOARCH=arm64 VERSION=${RELEASE_VERSION} make release

# Linux MIPS/MIPSLE
- run: GOOS=linux GOARCH=mips GOMIPS=softfloat VERSION=${RELEASE_VERSION} make release
- run: GOOS=linux GOARCH=mipsle GOMIPS=softfloat VERSION=${RELEASE_VERSION} make release

# FreeBSD X86
- run: GOOS=freebsd GOARCH=386 VERSION=${RELEASE_VERSION} make release
- run: GOOS=freebsd GOARCH=amd64 VERSION=${RELEASE_VERSION} make release

# FreeBSD ARM/ARM64
- run: GOOS=freebsd GOARCH=arm GOARM=6 VERSION=${RELEASE_VERSION} make release
- run: GOOS=freebsd GOARCH=arm64 VERSION=${RELEASE_VERSION} make release

- run: ls -l build/snirelay-*

- name: Create release
if: startsWith(github.ref, 'refs/tags/v')
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: See [CHANGELOG.md](./CHANGELOG.md) for the list of changes.
draft: false
prerelease: false
files: |
build/snirelay-*.tar.gz
build/snirelay-*.zip
53 changes: 53 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Docker

on:
push:
tags:
- 'v*'
branches:
- 'master'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: "VERSION=${GITHUB_REF##*/}"
26 changes: 26 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
'on':
'push':
'tags':
- 'v*'
'branches':
- '*'
'pull_request':

jobs:
golangci:
runs-on:
${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/[email protected]
with:
# This field is required. Dont set the patch version to always use
# the latest patch version.
version: v1.56.2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.vscode
/build
/relay
/snirelay
/sni_mapping.csv
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# snirelay changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog], and this project
adheres to [Semantic Versioning][semver].

[keepachangelog]: https://keepachangelog.com/en/1.0.0/

[semver]: https://semver.org/spec/v2.0.0.html

## [Unreleased]

[unreleased]: https://github.com/ameshkov/snirelay/compare/v1.0.0...HEAD

## [1.0.0] - 2024-03-25

* First version of snirelay.

[1.0.0]: https://github.com/ameshkov/snirelay/releases/tag/v1.0.0
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Step 1: Use the official Golang image as the build environment.
# This image includes all the tools needed to compile Go applications.
FROM golang:1.22 as builder

# Version will be passed as a part of the build.
ARG VERSION=dev

# Set the Current Working Directory inside the container.
WORKDIR /app

# Copy the local package files to the container's workspace.
COPY . .

# Build the Go app for a Linux system. The -o flag specifies the output binary
# name.
RUN VERSION=${VERSION} make build

# Step 2: Use a builder image to get the latest certificates.
FROM alpine:latest as certs

# Download the latest CA certificates
RUN apk --update add ca-certificates

# Step 3: Use a Docker multi-stage build to create a lean production image.
# Start from a scratch (empty) image to keep the image size small.
FROM scratch

# Copy the binary from the builder stage to the production image.
COPY --from=builder /app/snirelay /

# Copy the CA certificates from the certs image.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Expose listen ports.
EXPOSE 8443/tcp
EXPOSE 8080/tcp

ENTRYPOINT ["/snirelay", "-l", "0.0.0.0", "-p", "8080:8443"]
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 Andrey Meshkov

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.
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
NAME=snirelay
BASE_BUILDDIR=build
BUILDNAME=$(GOOS)-$(GOARCH)
BUILDDIR=$(BASE_BUILDDIR)/$(BUILDNAME)
VERSION?=v0.0-dev
VERSIONPKG=github.com/ameshkov/snirelay/internal/version

ifeq ($(GOOS),windows)
ext=.exe
archiveCmd=zip -9 -r $(NAME)-$(BUILDNAME)-$(VERSION).zip $(BUILDNAME)
else
ext=
archiveCmd=tar czpvf $(NAME)-$(BUILDNAME)-$(VERSION).tar.gz $(BUILDNAME)
endif

.PHONY: default
default: build

build: clean
CGO_ENABLED=0 go build -ldflags "-X $(VERSIONPKG).version=$(VERSION)" -o $(NAME)

release: check-env-release
mkdir -p $(BUILDDIR)
cp LICENSE $(BUILDDIR)/
cp README.md $(BUILDDIR)/
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "-X $(VERSIONPKG).version=$(VERSION)" -o $(BUILDDIR)/$(NAME)$(ext)
cd $(BASE_BUILDDIR) ; $(archiveCmd)

test:
go test -race -v -bench=. ./...

clean:
go clean
rm -rf $(BASE_BUILDDIR)

check-env-release:
@ if [ "$(GOOS)" = "" ]; then \
echo "Environment variable GOOS not set"; \
exit 1; \
fi
@ if [ "$(GOARCH)" = "" ]; then \
echo "Environment variable GOARCH not set"; \
exit 1; \
fi
Loading

0 comments on commit a22a3c8

Please sign in to comment.