Skip to content

Commit

Permalink
stage wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tprasadtp committed Apr 10, 2024
1 parent 75c4e54 commit fa5e214
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 31 deletions.
15 changes: 0 additions & 15 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ updates:
pull-request-branch-name:
separator: "-"

- package-ecosystem: docker
labels:
- "dependabot"
- "dep/docker"
- "luna/autoupdate"
target-branch: release/7.2
commit-message:
prefix: "chore(deps):"
directory: "/"
schedule:
interval: "weekly"
day: "saturday"
pull-request-branch-name:
separator: "-"

- package-ecosystem: github-actions
labels:
- "dependabot"
Expand Down
16 changes: 4 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,10 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: GoReleaser
uses: goreleaser/goreleaser-action@v5
id: goreleaser
with:
version: latest
args: release --clean --skip validate
env:
# Overrde to avoid tagging.
GORELEASER_CURRENT_TAG: 7.5.1-debug1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get Manifest Digest
- name: Build Images
run: task --verbose build-images

- name: Push Images and Create Manifest
id: get-manifest-digest
run: |
set -euo pipefail
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#syntax=docker/dockerfile:1.2
FROM debian:bookworm-20240311-slim as base
FROM debian@sha256:ccb33c3ac5b02588fc1d9e4fc09b952e433d0c54d8618d0ee1afadf1f3cf2455 as base

FROM base

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ See [Troubleshooting][] and [FAQ][]

## Building

Building requires `goreleaser`, and `docker` with `buildx` plugin.
Building requires `go-task`, `crane` and `docker` with `buildx` plugin.

[drop-in]: https://wiki.archlinux.org/title/systemd#Drop-in_files
[nss-resolve]: https://www.freedesktop.org/software/systemd/man/nss-resolve.html
Expand Down
173 changes: 173 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# SPDX-FileCopyrightText: Copyright 2024 Prasad Tengse
# SPDX-License-Identifier: MIT

# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

vars:
# Go coverage data directory is user's working directory + '.gocover'.
# Go benchmarks data directory is user's working director + 'benchmarks'.
GO_COVER_DIR: '{{ joinPath .ROOT_DIR ".gocover" }}'
GO_BENCHMARKS_DIR: '{{ joinPath .ROOT_DIR "benchmarks" }}'

tasks:
# -----------------------------------------------------------------
# Default Task. Shows List of available tasks.
#
# This intentionally lacks a desc field to hide it from help output.
# -----------------------------------------------------------------
default:
cmds:
- cmd: task --list
silent: true
# -----------------------------------------------------------------
# Creates a directory if not present.
# -----------------------------------------------------------------
internal:mkdir:
internal: true
label: mkdir
requires:
vars:
- DIRECTORY
status:
- >-
{{- if .DIRECTORY }}
test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
# Do not use long form flag --parents as it is not supported on macOS.
- cmd: mkdir -p {{.DIRECTORY|quote}}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'New-Item -ItemType Directory -Force -Path "{{.DIRECTORY}}"'
platforms:
- windows
# -----------------------------------------------------------------
# Removes files with PATTERN in the given DIRECTORY.
# -----------------------------------------------------------------
internal:rm-file-glob:
internal: true
label: "rm"
requires:
vars:
- DIRECTORY
- PATTERN
status:
- >-
{{- if .DIRECTORY }}
! test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
# Do not use long form flag --parents as it is not supported on macOS.
- cmd: rm -f {{ joinPath (.DIRECTORY | quote) .PATTERN }}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ joinPath .DIRECTORY .PATTERN }}"'
platforms:
- windows
# -----------------------------------------------------------------
# Removes an empty DIRECTORY.
# -----------------------------------------------------------------
internal:rmdir:
internal: true
label: "rmdir"
requires:
vars:
- DIRECTORY
status:
- >-
{{- if .DIRECTORY }}
! test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
- cmd: rmdir {{ .DIRECTORY | quote }}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ .DIRECTORY }}"'
platforms:
- windows
# -----------------------------------------------------------------
# Build Docker images
# -----------------------------------------------------------------
internal:build-script:
# internal: true
requires:
vars:
- "GIT_COMMIT"
- "VERSION"
cmds:
- task: internal:mkdir
vars:
DIRECTORY: "{{.DIST}}"
- cmd: ./scripts/build-script build -o=dist/protonwire main.commit={{.GIT_COMMIT}} main.version={{.VERSION}}
internal:build-image:
internal: true
requires:
vars:
- "PLATFORM"
- "GIT_COMMIT"
- "GIT_COMMIT_TIMESTAMP"
vars:
IMAGE_LABEL_FLAGS: >-
{{- printf `--label "%s=%s"` "org.opencontainers.image.revision" .GIT_COMMIT }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.created" .GIT_COMMIT_TIMESTAMP }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.vendor" "Prasad Tengse <tprasadtp@users.noreply.github.com>" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.source" "https://github.com/tprasadtp/protonvpn-docker" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.title" "protonwire" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.description" "ProtonVPN Wireguard Client" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.licenses" "GPLv3" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.documentation" "https://github.com/tprasadtp/protonvpn-docker" }}
{{- printf ` --label "%s=%s"` "io.artifacthub.package.readme-url" "https://raw.githubusercontent.com/tprasadtp/go-autotune/master/README.md" }}
IMAGE_TAG: '{{.GIT_COMMIT }}-{{.PLATFORM | replace "/" "-" }}'
IMAGE_TARBALL: '{{ printf "%s.tar" (joinPath "build" (.PLATFORM | replace "/" "-")) }}'
env:
DOCKER_BUILDKIT: "1"
cmds:
- cmd: cp Dockerfile dist/Dockerfile
- docker build {{.IMAGE_LABEL_FLAGS}} --tag=ghcr.io/tprasadtp/protonwire:{{.IMAGE_TAG}} --platform={{.PLATFORM}} dist/
- docker image save --output={{.IMAGE_TARBALL}} ghcr.io/tprasadtp/protonwire:{{.IMAGE_TAG}}
build-images:
desc: "Build Docker Images"
aliases:
- "images-build"
vars:
GIT_COMMIT:
sh: git -c log.showSignature=false show --format=%H --quiet HEAD
GIT_TREE_STATE:
sh: git -c log.showSignature=false status --porcelain
GIT_COMMIT_TIMESTAMP:
sh: git -c log.showSignature=false show --format=%cI --quiet HEAD
cmds:
- task: internal:build-script
vars:
DIST: "{{.DIST_DIR}}"
GIT_COMMIT: "{{.GIT_COMMIT}}"
VERSION: "dev"
- for: ["linux/amd64", "linux/arm64"]
task: internal:build-image
vars:
PLATFORM: "{{.ITEM}}"
DIST_DIR: "dist"
GIT_COMMIT: "{{.GIT_COMMIT}}"
GIT_COMMIT_TIMESTAMP: "{{.GIT_COMMIT_TIMESTAMP}}"
2 changes: 1 addition & 1 deletion docs/examples/podman/protonwire.container
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Notify=true
ContainerName=protonwire

# Runtime configuration
Image=ghcr.io/tprasadtp/protonwire:7
Image=ghcr.io/tprasadtp/protonwire:latest
Timezone=local
RunInit=true

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/tprasadtp/protonwire
module github.com/tprasadtp/protonvpn-docker

go 1.20

require github.com/Masterminds/semver/v3 v3.2.1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
90 changes: 90 additions & 0 deletions internal/cmd/semver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: Copyright 2024 Prasad Tengse
// SPDX-License-Identifier: GPLv3-only

// CLI tool to parse and extract semver versions.
package main

import (
"flag"
"fmt"
"io"
"os"
"strings"

"github.com/Masterminds/semver/v3"
)

func main() {
flag.Usage = func() {
help(os.Stderr)
}
flag.Parse()

if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "No commands specified!")
fmt.Fprintln(os.Stderr)
help(os.Stderr)
os.Exit(2)
}

switch strings.ToLower(os.Args[1]) {
case "major", "major-version", "get-major", "get-major-version":
version := validate(os.Args[2])
fmt.Println(version.Major())
case "minor", "minor-version", "get-minor", "get-minor-version":
version := validate(os.Args[2])
fmt.Println(version.Minor())
case "patch", "patch-version", "get-patch", "get-patch-version":
version := validate(os.Args[2])
fmt.Println(version.Patch())
case "pre-release", "pre-release-version", "get-pre-release", "get-pre-release-version",
"prerelease", "prerelease-version", "get-prerelease", "get-prerelease-version":
version := validate(os.Args[2])
fmt.Println(version.Prerelease())
case "build", "build-version", "get-build", "get-build-version",
"metadata", "metadata-version", "get-metadata", "get-metadata-version":
version := validate(os.Args[2])
fmt.Println(version.Metadata())
case "is-pre-release", "is-prerelease":
version := validate(os.Args[2])
if version.Prerelease() != "" {
fmt.Println("true")
} else {
fmt.Println("false")
}
case "help":
help(os.Stderr)
default:
fmt.Fprintf(os.Stderr, "Unknown commands: %s\n\n", os.Args[1:])
fmt.Fprintln(os.Stderr)
help(os.Stderr)
os.Exit(2)
}
}

func help(w io.Writer) {
fmt.Fprintln(w, "CLI to validate and extract semantic versions.")
fmt.Fprintln(w)
fmt.Fprintln(w, "USAGE: semver COMMAND VERSION")
fmt.Fprintln(w)
fmt.Fprintln(w, "COMMANDS:")
fmt.Fprintln(w, " validate Validates VERSION is a valid semver")
fmt.Fprintln(w, " major Extract major version from VERSION")
fmt.Fprintln(w, " minor Extract minor version from VERSION")
fmt.Fprintln(w, " minor Extract patch version from VERSION")
fmt.Fprintln(w, " pre-release Extract pre-release version from VERSION")
fmt.Fprintln(w, " metadata Extract metadata from VERSION")
fmt.Fprintln(w, " is-pre-release Prints true if VERSION is a pre-release otherwise print false")
fmt.Fprintln(w, " help Show this help message")
fmt.Fprintln(w)
}

func validate(input string) *semver.Version {
version, err := semver.StrictNewVersion(strings.TrimPrefix(input, "v"))

if err != nil {
fmt.Fprintf(os.Stderr, "Version(%s) is invalid: %s\n", input, err)
os.Exit(2)
}
return version
}
8 changes: 8 additions & 0 deletions scripts/goreleaser-wrapper → scripts/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ elif [[ $1 == "build" ]]; then
main.version=*)
PROTONWIRE_VERSION="${1##*=}"
;;
-main.version|main.version)
shift
PROTONWIRE_VERSION="${1}"
;;
main.commit=*)
PROTONWIRE_COMMIT="${1##*=}"
;;
-main.commit|main.commit)
shift
PROTONWIRE_COMMIT="${1}"
;;
-o=*)
output_file="${1##*=}"
;;
Expand Down

0 comments on commit fa5e214

Please sign in to comment.