-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM golang:1.19.3-alpine as builder | ||
|
||
RUN apk --no-cache add git ca-certificates gcc g++ upx | ||
|
||
WORKDIR /go/src/github.com/go-sonic/ | ||
|
||
RUN git clone --recursive --depth 1 https://github.com/go-sonic/sonic.git | ||
|
||
WORKDIR /go/src/github.com/go-sonic/sonic | ||
|
||
ENV GOPROXY=https://goproxy.cn | ||
RUN CGO_ENABLED=1 GOOS=linux go build -o sonic -ldflags="-s -w" -trimpath . && \ | ||
upx sonic -o upx_sonic && \ | ||
mv -f upx_sonic sonic | ||
|
||
RUN mkdir -p /app/conf && \ | ||
mkdir /app/resources && \ | ||
cp -r /go/src/github.com/go-sonic/sonic/sonic /app/ && \ | ||
cp -r /go/src/github.com/go-sonic/sonic/conf /app/conf && \ | ||
cp -r /go/src/github.com/go-sonic/sonic/resources /app/ && \ | ||
cp /go/src/github.com/go-sonic/sonic/scripts/docker_init.sh /app/ | ||
|
||
FROM alpine:latest as prod | ||
|
||
COPY --from=builder /app/ /app/ | ||
|
||
VOLUME /sonic | ||
EXPOSE 8080 | ||
|
||
WORKDIR /sonic | ||
CMD /app/docker_init.sh && /app/sonic -config /sonic/conf/config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/bin/sh | ||
|
||
verbose="${VERBOSE:-0}" | ||
|
||
if [ "$verbose" -gt '0' ] | ||
then | ||
set -x | ||
debug_flags='-D' | ||
else | ||
set +x | ||
debug_flags='' | ||
fi | ||
|
||
set -e -f -u | ||
|
||
# Require these to be set. The channel value is validated later. | ||
channel="${CHANNEL:?please set CHANNEL}" | ||
commit="${COMMIT:?please set COMMIT}" | ||
dist_dir="${DIST_DIR:?please set DIST_DIR}" | ||
readonly channel commit dist_dir | ||
|
||
if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ] | ||
then | ||
version="$( sh ./scripts/make/version.sh )" | ||
else | ||
version="$VERSION" | ||
fi | ||
readonly version | ||
|
||
# Allow users to use sudo. | ||
sudo_cmd="${SUDO:-}" | ||
readonly sudo_cmd | ||
|
||
docker_platforms="\ | ||
linux/386,\ | ||
linux/amd64,\ | ||
linux/arm/v6,\ | ||
linux/arm/v7,\ | ||
linux/arm64,\ | ||
linux/ppc64le" | ||
readonly docker_platforms | ||
|
||
build_date="$( date -u +'%Y-%m-%dT%H:%M:%SZ' )" | ||
readonly build_date | ||
|
||
# Set DOCKER_IMAGE_NAME to 'go-sonic/sonic' if you want (and are allowed) | ||
# to push to DockerHub. | ||
docker_image_name="go-sonic/sonic" | ||
readonly docker_image_name | ||
|
||
# Set DOCKER_OUTPUT to 'type=image,name=adguard/adguard-home,push=true' if you | ||
# want (and are allowed) to push to DockerHub. | ||
# | ||
# If you want to inspect the resulting image using commands like "docker image | ||
# ls", change type to docker and also set docker_platforms to a single platform. | ||
# | ||
# See https://github.com/docker/buildx/issues/166. | ||
docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}" | ||
readonly docker_output | ||
|
||
case "$channel" | ||
in | ||
('release') | ||
docker_image_full_name="${docker_image_name}:${version}" | ||
docker_tags="--tag ${docker_image_name}:latest" | ||
;; | ||
('beta') | ||
docker_image_full_name="${docker_image_name}:${version}" | ||
docker_tags="--tag ${docker_image_name}:beta" | ||
;; | ||
('edge') | ||
# Don't set the version tag when pushing to the edge channel. | ||
docker_image_full_name="${docker_image_name}:edge" | ||
docker_tags='' | ||
;; | ||
('development') | ||
docker_image_full_name="${docker_image_name}" | ||
docker_tags='' | ||
;; | ||
(*) | ||
echo "invalid channel '$channel', supported values are\ | ||
'development', 'edge', 'beta', and 'release'" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
readonly docker_image_full_name docker_tags | ||
|
||
# Copy the binaries into a new directory under new names, so that it's eaiser to | ||
# COPY them later. DO NOT remove the trailing underscores. See file | ||
# scripts/make/Dockerfile. | ||
dist_docker="${dist_dir}/docker" | ||
readonly dist_docker | ||
|
||
mkdir -p "$dist_docker" | ||
cp -R "${dist_dir}/"\ | ||
"${dist_docker}/" | ||
|
||
|
||
# Don't use quotes with $docker_tags and $debug_flags because we want word | ||
# splitting and or an empty space if tags are empty. | ||
$sudo_cmd docker\ | ||
$debug_flags\ | ||
buildx build\ | ||
--build-arg BUILD_DATE="$build_date"\ | ||
--build-arg DIST_DIR="$dist_dir"\ | ||
--build-arg VCS_REF="$commit"\ | ||
--build-arg VERSION="$version"\ | ||
--output "$docker_output"\ | ||
--platform "$docker_platforms"\ | ||
$docker_tags\ | ||
-t "$docker_image_full_name"\ | ||
-f ./scripts/make/Dockerfile\ | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
check_and_copy() { | ||
if [ ! -e /sonic/$1 ]; then | ||
mkdir -p /sonic/$1 | ||
cp -Rf /app/$1/* /sonic/$1/ | ||
fi | ||
} | ||
|
||
make_and_copy() { | ||
mkdir -p /sonic/$1 | ||
cp -Rf /app/$1/* /sonic/$1/ | ||
} | ||
|
||
make_and_copy 'resources/admin' | ||
make_and_copy 'resources/template/common' | ||
check_and_copy 'conf' | ||
check_and_copy 'resources/template/theme' | ||
|