This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
forked from elgs/filesync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emcniece/feat/dockerize
Feat/dockerize
- Loading branch information
Showing
14 changed files
with
474 additions
and
159 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 |
---|---|---|
|
@@ -3,4 +3,9 @@ bin | |
pkg | ||
out | ||
.idea | ||
gsyncd.iml | ||
gsyncd.iml | ||
build | ||
.env | ||
/Godeps | ||
/vendor | ||
/demo |
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,13 @@ | ||
FROM busybox:ubuntu-14.04 | ||
MAINTAINER CausticLab | ||
|
||
ENV FILESYNC_RELEASE v0.0.1 | ||
|
||
ADD https://github.com/CausticLab/filesync/releases/download/${RGON_EXEC_RELEASE}/filesync-linux-amd64.tar.gz /tmp/filesync.tar.gz | ||
RUN tar -zxvf /tmp/filesync -C /usr/local/bin \ | ||
&& mv /usr/local/bin/filesync-linux-amd64 /usr/local/bin/filesync \ | ||
&& chmod +x /usr/local/bin/filesync \ | ||
&& rm /tmp/filesync | ||
RUN mkdir /share | ||
|
||
ENTRYPOINT ["/usr/local/bin/filesync"] |
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,8 @@ | ||
FROM busybox:ubuntu-14.04 | ||
MAINTAINER CausticLab | ||
|
||
ADD build/filesync-linux-amd64 /usr/local/bin/filesync | ||
RUN chmod +x /usr/local/bin/filesync | ||
RUN mkdir /share | ||
|
||
ENTRYPOINT ["/usr/local/bin/filesync"] |
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,89 @@ | ||
# These env vars have to be set in the CI | ||
# GITHUB_TOKEN | ||
# DOCKER_HUB_TOKEN | ||
|
||
.PHONY: build deps test release clean push image ci-compile build-dir ci-dist dist-dir ci-release version help | ||
|
||
PROJECT := filesync | ||
PLATFORM := linux | ||
ARCH := amd64 | ||
DOCKER_IMAGE := causticlab/$(PROJECT) | ||
|
||
VERSION := $(shell cat VERSION) | ||
GITSHA := $(shell git rev-parse --short HEAD) | ||
|
||
all: help | ||
|
||
help: | ||
@echo "make build - build binary for the target environment" | ||
@echo "make deps - install build dependencies" | ||
@echo "make vet - run vet & gofmt checks" | ||
@echo "make test - run tests" | ||
@echo "make clean - Duh!" | ||
@echo "make release - tag with version and trigger CI release build" | ||
@echo "make image - build release image" | ||
@echo "make dev-image - build development image" | ||
@echo "make dockerhub - build and push image to Docker Hub" | ||
@echo "make version - show app version" | ||
|
||
build: build-dir | ||
CGO_ENABLED=1 GOOS=$(PLATFORM) GOARCH=$(ARCH) godep go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA)" -o build/$(PROJECT)-$(PLATFORM)-$(ARCH) -v | ||
|
||
deps: | ||
go get golang.org/x/sys/unix | ||
go get github.com/tools/godep | ||
go get github.com/mattn/go-sqlite3 | ||
go get github.com/bitly/go-simplejson | ||
go get github.com/howeyc/fsnotify | ||
go get github.com/codegangsta/martini | ||
go get github.com/codegangsta/martini-contrib/encoder | ||
godep save | ||
|
||
release: | ||
git tag `cat VERSION` | ||
git push origin master --tags | ||
|
||
clean: | ||
go clean | ||
rm -fr ./build | ||
rm -fr ./dist | ||
|
||
dockerhub: image | ||
@echo "Pushing $(DOCKER_IMAGE):$(VERSION)" | ||
docker push $(DOCKER_IMAGE):$(VERSION) | ||
|
||
image: | ||
docker build -t $(DOCKER_IMAGE):$(VERSION) -f Dockerfile . | ||
|
||
dev-image: | ||
docker build -t $(DOCKER_IMAGE):dev -f Dockerfile.dev . | ||
|
||
version: | ||
@echo $(VERSION) $(GITSHA) | ||
|
||
ci-compile: build-dir | ||
CGO_ENABLED=1 GOOS=$(PLATFORM) GOARCH=$(ARCH) go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA) -w -s" -a -o build/$(PROJECT)-$(PLATFORM)-$(ARCH)/$(PROJECT) | ||
|
||
build-dir: | ||
@rm -rf build && mkdir build | ||
|
||
dist-dir: | ||
@rm -rf dist && mkdir dist | ||
|
||
ci-dist: ci-compile dist-dir | ||
$(eval FILES := $(shell ls build)) | ||
@for f in $(FILES); do \ | ||
(cd $(shell pwd)/build/$$f && tar -cvzf ../../dist/$$f.tar.gz *); \ | ||
(cd $(shell pwd)/dist && shasum -a 256 $$f.tar.gz > $$f.sha256); \ | ||
(cd $(shell pwd)/dist && md5sum $$f.tar.gz > $$f.md5); \ | ||
echo $$f; \ | ||
done | ||
@cp -r $(shell pwd)/dist/* $(CIRCLE_ARTIFACTS) | ||
ls $(CIRCLE_ARTIFACTS) | ||
|
||
ci-release: | ||
@previous_tag=$$(git describe --abbrev=0 --tags $(VERSION)^); \ | ||
comparison="$$previous_tag..HEAD"; \ | ||
if [ -z "$$previous_tag" ]; then comparison=""; fi; \ | ||
changelog=$$(git log $$comparison --oneline --no-merges --reverse); \ | ||
github-release $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME) $(VERSION) master "**Changelog**<br/>$$changelog" 'dist/*' |
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 |
---|---|---|
@@ -1,48 +1,115 @@ | ||
Filesync | ||
=== | ||
# Filesync | ||
|
||
Filesync is a utility written in Golang which helps you to keep the files on the client up to date with the files on the server. Only the changed parts of files on the server are downloaded. Therefore it's great to synchronize your huge, and frequently changing files. | ||
|
||
Installation | ||
=== | ||
`go get github.com/elgs/filesync/gsync` | ||
|
||
Server | ||
=== | ||
Run | ||
--- | ||
`gsync server.json` | ||
Configuration | ||
--- | ||
server.json | ||
```json | ||
{ | ||
"mode": "server", | ||
"ip": "0.0.0.0", | ||
"port": 6776, | ||
"monitors": { | ||
"home_elgs_desktop_a": "/home/elgs/Desktop/a", | ||
"home_elgs_desktop_b": "/home/elgs/Desktop/b" | ||
} | ||
} | ||
``` | ||
|
||
|
||
Client | ||
=== | ||
Run | ||
--- | ||
`gsync client.json` | ||
Configuration | ||
--- | ||
client.json | ||
```json | ||
{ | ||
"mode": "client", | ||
"ip": "127.0.0.1", | ||
"port": 6776, | ||
"monitors": { | ||
"home_elgs_desktop_a": "/home/elgs/Desktop/c", | ||
"home_elgs_desktop_b": "/home/elgs/Desktop/d" | ||
} | ||
} | ||
Forked from github.com/elgs/filesync/gsync | ||
|
||
## Requirements | ||
|
||
Needs access to `glibc` to compile properly, and so `busybox:ubuntu-14.04` is the selected base image. | ||
|
||
## Local Usage | ||
|
||
Install dependencies: | ||
|
||
```sh | ||
make deps | ||
``` | ||
|
||
Run locally with config files (modify paths before running): | ||
|
||
```sh | ||
# Server | ||
go run gsync.go gsync/server.json | ||
|
||
# Client | ||
go run gsync.go gsync/client.json | ||
``` | ||
|
||
Alternatively, set environment variables (examples in [/.env](/.env)): | ||
|
||
```sh | ||
# Server | ||
export FILESYNC_MODE=server | ||
export FILESYNC_PORT=6776 | ||
export FILESYNC_IP=0.0.0.0 | ||
export FILESYNC_PATH=/tmp/share | ||
|
||
go run gsync.go | ||
``` | ||
|
||
Build package (requires `glibc`, won't work on OSX): | ||
|
||
```sh | ||
make build | ||
``` | ||
|
||
Build Docker image: | ||
|
||
```sh | ||
make dev-image | ||
make image | ||
``` | ||
|
||
## Demo | ||
|
||
The [docker-compose.yml](/docker-compose.yml) details a setup with a server and 2 clients. It will create a `./demo/` directory with 3 subfolders: `server`, `client1`, and `client2`. Each subfolder is volumed as `/share/` inside each container. | ||
|
||
As files in `./demo/server` are modified, they will be altered in `./demo/client1` and `./demo/client2`. | ||
|
||
Run Docker-Compose cluster: | ||
|
||
```sh | ||
docker-compose up -d | ||
``` | ||
|
||
Check directories: | ||
|
||
```sh | ||
ls -al ./demo/server | ||
ls -al ./demo/client1 | ||
ls -al ./demo/client2 | ||
``` | ||
|
||
Add a file to server volume: | ||
|
||
```sh | ||
echo "testing 123" > ./demo/server/test1 | ||
``` | ||
|
||
Check directories again: | ||
|
||
```sh | ||
ls -al ./demo/server | ||
ls -al ./demo/client1 | ||
ls -al ./demo/client2 | ||
``` | ||
|
||
At this point, the `./demo/client*` directories should contain a `test1` file. | ||
|
||
## Notes | ||
|
||
### Docker Environment | ||
|
||
While the server configuration can be set to an IP of `0.0.0.0` (accepts traffic from anywhere), the clients need a specific address to connect to. If running locally, the clients can be set to connect to `127.0.0.1` - but this will not work in a Dockerized environment. | ||
|
||
The Docker-Compose.yml file contains `links: [fs-server:fs-server]` which enables the clients to contact the server container at `http://fs-server`. This is supported in a Rancher environment as well. | ||
|
||
### Rancher Environment | ||
|
||
Filesync can be used as a way to share files between hosts. Container deployment can be controlled by assigning labels and using the Rancher scheduling system. | ||
|
||
By labelling the primary host with `filesync=server`, these labels can be used to add a Filesync server and multiple clients: | ||
|
||
```yml | ||
# Server | ||
labels: | ||
io.rancher.scheduler.affinity:host_label: filesync=server | ||
|
||
# Client | ||
labels: | ||
io.rancher.scheduler.global: 'true' | ||
io.rancher.scheduler.affinity:host_label_ne: filesync=server | ||
``` | ||
The host labelled with `filesync=server` will receive a Filesync server container, and all other hosts (`io.rancher.scheduler.global: 'true'`) not labelled with this (`host_label_ne: filesync=server`) will receive a client container. |
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 @@ | ||
v0.0.1 |
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
Oops, something went wrong.