Skip to content

Commit

Permalink
Merge pull request #794 from alexadhy/feature/docker-refactorings
Browse files Browse the repository at this point in the history
Feature/docker refactorings
  • Loading branch information
jdknives committed Jun 16, 2021
2 parents e1ab759 + 7ba77a6 commit 7299c7e
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 60 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ VERSION := $(shell git describe)
RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ"
DATE := $(shell date -u $(RFC_3339))
COMMIT := $(shell git rev-list -1 HEAD)
BRANCH := latest

PROJECT_BASE := github.com/skycoin/skywire
DMSG_BASE := github.com/skycoin/dmsg
Expand Down Expand Up @@ -133,6 +134,9 @@ build-deploy: ## Build for deployment Docker images
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/apps/skysocks ./cmd/apps/skysocks
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/apps/skysocks-client ./cmd/apps/skysocks-client

build-docker: ## Build docker image
./ci_scripts/docker-push.sh -t ${BRANCH} -b

github-release: ## Create a GitHub release
goreleaser --rm-dist

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $ cd skywire
$ make build; make install

# OR build docker image
$ ./ci_scripts/docker-push.sh -t $(git rev-parse --abbrev HEAD) -b
$ ./ci_scripts/docker-push.sh -t $(git rev-parse --abbrev-ref HEAD) -b
```

Skywire can be statically built. For instructions check [the docs](docs/static-builds.md).
Expand All @@ -44,7 +44,7 @@ Docker container will create config automatically for you, should you want to ru

```bash
$ docker run --rm -v <YOUR_CONFIG_DIR>:/opt/skywire \
skycoin/skywire:latest skywire-cli gen-config --is-hypervisor
skycoin/skywire:test skywire-cli gen-config --is-hypervisor
```

After starting up the visor, the UI will be exposed by default on `localhost:8000`.
Expand All @@ -62,8 +62,7 @@ Or from docker image:

```bash
$ docker run --rm -v <YOUR_CONFIG_DIR>:/opt/skywire \
skycoin/skywire:latest skywire-cli update-config hypervisor-pks <public-key>

skycoin/skywire:test skywire-cli update-config hypervisor-pks <public-key>
```

## Run `skywire-visor`
Expand All @@ -80,7 +79,10 @@ $ sudo skywire-visor -c skywire-config.json
Or from docker image:

```bash
docker run --rm -p 8000:8000 -v <YOUR_CONFIG_DIR>:/opt/skywire --name=skywire skycoin/skywire:latest skywire-visor
# with custom config mounted on docker volume
$ docker run --rm -p 8000:8000 -v <YOUR_CONFIG_DIR>:/opt/skywire --name=skywire skycoin/skywire:test skywire-visor -c /opt/skywire/<YOUR_CONFIG_NAME>.json
# without custom config (config is automatically generated)
$ docker run --rm -p 8000:8000 --name=skywire skycoin/skywire:test skywire-visor
```

`skywire-visor` can be run on Windows. The setup requires additional setup steps that are specified
Expand Down
11 changes: 2 additions & 9 deletions ci_scripts/docker-push.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/usr/bin/env bash

function extra_ldflags() {
local build_dir="github.com/skycoin/dmsg/buildinfo"
local version="$(git describe)"
local commit="$(git rev-parse HEAD)"
local build_date="$(date -u "+%Y-%m-%d%T%H:%M:%SZ")"
echo "-X ${build_dir}.version=${version} -X ${build_dir}.commit=${commit} -X ${build_dir}.date=${build_date}"
}

function print_usage() {
echo "Use: $0 [-t <docker_image_tag_name>] [-p | -b]"
echo "use -p for push (it builds and push the image)"
Expand All @@ -22,7 +14,6 @@ fi
function docker_build() {
docker image build \
--tag=skycoin/skywire:"$tag" \
--build-arg BUILDINFO_LDFLAGS="$(extra_ldflags)" \
-f ./docker/images/visor/Dockerfile .
}

Expand All @@ -40,6 +31,8 @@ while getopts ":t:pb" o; do
tag="test"
elif [[ $tag == "master" ]]; then
tag="latest"
else
tag=$tag
fi
;;
p)
Expand Down
43 changes: 22 additions & 21 deletions docker/images/visor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@ ENV CGO_ENABLED=${CGO_ENABLED} \
GOARCH=amd64 \
GO111MODULE=on

COPY . skywire
COPY . /skywire

WORKDIR skywire

RUN echo $BUILDINFO_LDFLAGS

RUN go build -mod=vendor -tags netgo -ldflags="-w -s ${BUILDINFO_LDFLAGS}" \
-o skywire-visor cmd/skywire-visor/skywire-visor.go &&\
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o skywire-cli ./cmd/skywire-cli &&\
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o ./apps/skychat ./cmd/apps/skychat &&\
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o ./apps/skysocks ./cmd/apps/skysocks &&\
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o ./apps/skysocks-client ./cmd/apps/skysocks-client && \
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o ./apps/vpn-server ./cmd/apps/vpn-server && \
go build -mod=vendor -ldflags="-w -s ${BUILDINFO_LDFLAGS}" -o ./apps/vpn-client ./cmd/apps/vpn-client
WORKDIR /skywire

RUN apk add --no-cache make && \
sh -c /skywire/docker/images/visor/install-preq.sh && \
make host-apps && \
make build-deploy && \
mkdir -p /apps && \
cp ./apps/vpn-server /apps/ && \
cp ./apps/vpn-client /apps/ && \
cp ./apps/skysocks /apps/ && \
cp ./apps/skychat /apps/

## Resulting image
FROM ${base} as visor-runner

COPY --from=builder /go/skywire/skywire-visor skywire-visor
COPY --from=builder /go/skywire/apps /apps
COPY --from=builder /go/skywire/docker/images/visor/update.sh update.sh
COPY --from=builder /go/skywire/skywire-cli bin/skywire-cli
COPY --from=builder /go/skywire/docker/images/visor/entrypoint.sh entrypoint.sh
COPY --from=builder /skywire/docker/images/visor/install-preq.sh /release/install-preq.sh
COPY --from=builder /skywire/docker/images/visor/entrypoint.sh /entrypoint.sh
COPY --from=builder /release /release
COPY --from=builder /apps /apps

RUN sh -c /release/install-preq.sh \
&& rm -rf /release/install-preq.sh \
&& mkdir -p /opt/skywire

RUN ./update.sh
STOPSIGNAL SIGINT

ENTRYPOINT [ "./entrypoint.sh" ]
ENTRYPOINT [ "/entrypoint.sh" ]

# default target
FROM visor-runner
FROM visor-runner
59 changes: 39 additions & 20 deletions docker/images/visor/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
#!/bin/sh
#!/usr/bin/env bash

test -d /opt/skywire || {
echo "no docker volume mounted, exiting..."
exit 1
set -x

## PID of skywire-visor
pid=0

default_config_path=/opt/skywire/config.json

gen_default_config() {
echo "no config found, generating one...."
/release/skywire-cli visor gen-config -o "$default_config_path" -r --is-hypervisor
sed -i 's/localhost//g' "$default_config_path"
echo "config generated"
}

sigint_handler() {
if [ $pid -ne 0 ]; then
kill -INT "$pid"
wait "$pid"
fi
exit 130;
}

if [ "$#" -ne 1 ]; then
test -f /opt/skywire/skywire-config.json || {
echo "no config found, generating one...." &&
/bin/skywire-cli visor gen-config -o /opt/skywire/skywire-config.json -r --is-hypervisor &&
sed -i 's/localhost//g' /opt/skywire/skywire-config.json &&
echo "config generated." &&
exit 0
}
fi
trap 'kill ${!}; sigint_handler' INT

cmd="$(echo "$1" | tr -d '[:space:]')"
shift 1

echo "$@"

case "$cmd" in
skywire-visor)
./"$cmd" -c /opt/skywire/skywire-config.json "$@"
case "$1" in
-c)
/release/"$cmd" "$@" &
;;
*)
gen_default_config
/release/"$cmd" -c "$default_config_path" "$@" &
;;
esac
;;
skywire-cli)
/bin/skywire-cli "$@"
;;
skychat | skysocks | skysocks-client)
/apps/"$cmd" "$@"
/release/"$cmd" "$@" &
;;
esac

pid="$!"

while true
do
wait ${!}
done
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ if type apt > /dev/null; then
fi

if type apk > /dev/null; then

apk update
apk upgrade
apk add --no-cache ca-certificates openssl iproute2
apk update
apk add --no-cache ca-certificates openssl iproute2 bash
update-ca-certificates --fresh
apk add iproute2
fi

0 comments on commit 7299c7e

Please sign in to comment.