all: upd go, chlog, tools

This commit is contained in:
Ainar Garipov
2022-04-06 18:27:21 +03:00
parent b2052f2ef1
commit d17c6c6bb3
22 changed files with 389 additions and 189 deletions

View File

@@ -90,14 +90,15 @@ Required environment:
### `go-build.sh`: Build The Backend
Optional environment:
* `BUILD_TIME`: If set, overrides the build time information. Useful for
reproducible builds.
* `GOARM`: ARM processor options for the Go compiler.
* `GOMIPS`: ARM processor options for the Go compiler.
* `GO`: set an alternative name for the Go compiler.
* `OUT`: output binary name.
* `PARALLELISM`: set the maximum number of concurrently run build commands
(that is, compiler, linker, etc.).
* `SOURCE_DATE_EPOCH`: the [standardized][repr] environment variable for the
Unix epoch time of the latest commit in the repository. If set, overrides
the default obtained from Git. Useful for reproducible builds.
* `VERBOSE`: verbosity level. `1` shows every command that is run and every
Go package that is processed. `2` also shows subcommands and environment.
The default value is `0`, don't be verbose.
@@ -107,6 +108,8 @@ Optional environment:
Required environment:
* `CHANNEL`: release channel, see above.
[repr]: https://reproducible-builds.org/docs/source-date-epoch/
### `go-deps.sh`: Install Backend Dependencies

View File

@@ -63,33 +63,31 @@ is_little_endian() {
# Function check_required checks if the required software is available on the
# machine. The required software:
#
# curl
# unzip (macOS) / tar (other unixes)
#
# curl/wget are checked in function configure.
check_required() {
required_darwin="unzip"
required_unix="tar"
readonly required_darwin required_unix
# Split with space.
required="curl"
case "$os"
in
('freebsd'|'linux'|'openbsd')
required="$required $required_unix"
required="$required_unix"
;;
('darwin')
required="$required $required_darwin"
required="$required_darwin"
;;
(*)
# Generally shouldn't happen, since the OS has already been
# validated.
# Generally shouldn't happen, since the OS has already been validated.
error_exit "unsupported operating system: '$os'"
;;
esac
readonly required
# Don't use quotes to get word splitting.
for cmd in ${required}
for cmd in $required
do
log "checking $cmd"
if ! is_command "$cmd"
@@ -206,6 +204,9 @@ set_os() {
('OpenBSD')
os='openbsd'
;;
(*)
error_exit "unsupported operating system: '$os'"
;;
esac
fi
@@ -257,6 +258,9 @@ set_cpu() {
fi
cpu="${cpu}_softfloat"
;;
(*)
error_exit "unsupported cpu type: $cpu"
;;
esac
fi
@@ -314,6 +318,41 @@ fix_freebsd() {
fi
}
# download_curl uses curl(1) to download a file. The first argument is the URL.
# The second argument is optional and is the output file.
download_curl() {
curl_output="${2:-}"
if [ "$curl_output" = '' ]
then
curl -L -S -s "$1"
else
curl -L -S -o "$curl_output" -s "$1"
fi
}
# download_wget uses wget(1) to download a file. The first argument is the URL.
# The second argument is optional and is the output file.
download_wget() {
wget_output="${2:--}"
wget --no-verbose -O "$wget_output" "$1"
}
# Function set_download_func sets the appropriate function for downloading
# files.
set_download_func() {
if is_command 'curl'
then
# Go on and use the default, download_curl.
return 0
elif is_command 'wget'
then
download_func='download_wget'
else
error_exit "either curl or wget is required to install AdGuard Home via this script"
fi
}
# Function set_sudo_cmd sets the appropriate command to run a command under
# superuser privileges.
set_sudo_cmd() {
@@ -337,6 +376,7 @@ configure() {
set_os
set_cpu
fix_darwin
set_download_func
set_sudo_cmd
check_out_dir
@@ -401,11 +441,11 @@ rerun_with_root() {
log 'restarting with root privileges'
# Group curl together with an echo, so that if curl fails before producing
# any output, the echo prints an exit command for the following shell to
# execute to prevent it from getting an empty input and exiting with a zero
# code in that case.
{ curl -L -S -s "$script_url" || echo 'exit 1'; }\
# Group curl/wget together with an echo, so that if the former fails before
# producing any output, the latter prints an exit command for the following
# shell to execute to prevent it from getting an empty input and exiting
# with a zero code in that case.
{ "$download_func" "$script_url" || echo 'exit 1'; }\
| $sudo_cmd sh -s -- -c "$channel" -C "$cpu" -O "$os" -o "$out_dir" "$r" "$u" "$v"
# Exit the script. Since if the code of the previous pipeline is non-zero,
@@ -418,7 +458,7 @@ rerun_with_root() {
download() {
log "downloading package from $url -> $pkg_name"
if ! curl -s "$url" --output "$pkg_name"
if ! "$download_func" "$url" "$pkg_name"
then
error_exit "cannot download the package from $url into $pkg_name"
fi
@@ -467,7 +507,7 @@ handle_existing() {
return 0
fi
if [ "$( ls -1 -A $agh_dir )" != '' ]
if [ "$( ls -1 -A "$agh_dir" )" != '' ]
then
log 'the existing AdGuard Home installation is detected'
@@ -539,6 +579,7 @@ cpu=''
os=''
out_dir='/opt'
pkg_ext='tar.gz'
download_func='download_curl'
sudo_cmd='sudo'
parse_opts "$@"

View File

@@ -5,22 +5,26 @@ FROM alpine:3.13
ARG BUILD_DATE
ARG VERSION
ARG VCS_REF
LABEL maintainer="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.url="https://adguard.com/adguard-home.html" \
org.opencontainers.image.source="https://github.com/AdguardTeam/AdGuardHome" \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.vendor="AdGuard" \
org.opencontainers.image.title="AdGuard Home" \
org.opencontainers.image.description="Network-wide ads & trackers blocking DNS server" \
org.opencontainers.image.licenses="GPL-3.0"
LABEL\
maintainer="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.authors="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.description="Network-wide ads & trackers blocking DNS server" \
org.opencontainers.image.documentation="https://github.com/AdguardTeam/AdGuardHome/wiki/" \
org.opencontainers.image.licenses="GPL-3.0" \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.source="https://github.com/AdguardTeam/AdGuardHome" \
org.opencontainers.image.title="AdGuard Home" \
org.opencontainers.image.url="https://adguard.com/en/adguard-home/overview.html" \
org.opencontainers.image.vendor="AdGuard" \
org.opencontainers.image.version=$VERSION
# Update certificates.
RUN apk --no-cache --update add ca-certificates libcap tzdata && \
rm -rf /var/cache/apk/* && \
mkdir -p /opt/adguardhome/conf /opt/adguardhome/work && \
chown -R nobody: /opt/adguardhome
rm -rf /var/cache/apk/* && \
mkdir -p /opt/adguardhome/conf /opt/adguardhome/work && \
chown -R nobody: /opt/adguardhome
ARG DIST_DIR
ARG TARGETARCH

View File

@@ -156,7 +156,8 @@ linux ppc64le - - -
openbsd amd64 - - -
openbsd arm64 - - -
windows 386 - - -
windows amd64 - - -"
windows amd64 - - -
windows arm64 - - -"
readonly platforms
# Function build builds the release for one platform. It builds a binary, an

View File

@@ -65,9 +65,9 @@ then
fi
readonly version
# Set date and time of the current build unless already set.
buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}"
readonly buildtime
# Set date and time of the latest commit unless already set.
committime="${SOURCE_DATE_EPOCH:-$( git log -1 --pretty=%ct )}"
readonly committime
# Set the linker flags accordingly: set the release channel and the current
# version as well as goarm and gomips variable values, if the variables are set
@@ -78,7 +78,7 @@ readonly version_pkg
ldflags="-s -w"
ldflags="${ldflags} -X ${version_pkg}.version=${version}"
ldflags="${ldflags} -X ${version_pkg}.channel=${channel}"
ldflags="${ldflags} -X ${version_pkg}.buildtime=${buildtime}"
ldflags="${ldflags} -X ${version_pkg}.committime=${committime}"
if [ "${GOARM:-}" != '' ]
then
ldflags="${ldflags} -X ${version_pkg}.goarm=${GOARM}"

View File

@@ -52,7 +52,7 @@ trap not_found EXIT
go_version="$( "${GO:-go}" version )"
readonly go_version
go_min_version='go1.16'
go_min_version='go1.17'
go_version_msg="
warning: your go version (${go_version}) is different from the recommended minimal one (${go_min_version}).
if you have the version installed, please set the GO environment variable.
@@ -134,9 +134,10 @@ underscores() {
-e '_bsd.go'\
-e '_darwin.go'\
-e '_freebsd.go'\
-e '_openbsd.go'\
-e '_linux.go'\
-e '_little.go'\
-e '_nolinux.go'\
-e '_openbsd.go'\
-e '_others.go'\
-e '_test.go'\
-e '_unix.go'\
@@ -209,7 +210,7 @@ exit_on_output method_const
exit_on_output underscores
exit_on_output gofumpt --extra -l -s .
exit_on_output gofumpt --extra -e -l .
golint --set_exit_status ./...

View File

@@ -35,10 +35,13 @@ fi
readonly race_flags
go="${GO:-go}"
readonly go
count_flags='--count=1'
cover_flags='--coverprofile=./coverage.txt'
shuffle_flags='--shuffle=on'
timeout_flags="${TIMEOUT_FLAGS:---timeout=30s}"
readonly go timeout_flags cover_flags count_flags
readonly count_flags cover_flags shuffle_flags timeout_flags
"$go" test "$count_flags" "$cover_flags" "$race_flags" "$timeout_flags" "$x_flags" "$v_flags" ./...
"$go" test "$count_flags" "$cover_flags" "$race_flags" "$shuffle_flags" "$timeout_flags"\
"$x_flags" "$v_flags" ./...

View File

@@ -86,6 +86,7 @@ in
# minor release. If the current commit is the new minor release,
# num_commits_since_minor is zero.
num_commits_since_minor="$( git rev-list "${last_minor_zero}..HEAD" | wc -l )"
# The output of darwin's implementation of wc needs to be trimmed from
# redundant spaces.
num_commits_since_minor="$( echo "$num_commits_since_minor" | tr -d '[:space:]' )"