Skip to content

Commit c70287e

Browse files
committed
add docker image
1 parent c3bbe71 commit c70287e

File tree

14 files changed

+341
-3387
lines changed

14 files changed

+341
-3387
lines changed

.github/resources/benchmark_comparison.svg

Lines changed: 0 additions & 1695 deletions
This file was deleted.

.github/resources/memory_usage_over_time.svg

Lines changed: 0 additions & 1603 deletions
This file was deleted.

.github/workflows/goreleaser.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ jobs:
1818
fetch-depth: 0
1919

2020
- name: Set up Go
21-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
2222

23-
- name: Install Protoc
24-
uses: arduino/setup-protoc@v3
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
2525

26-
- name: Install protoc-gen-go
27-
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
2828

29-
- name: Install protoc-gen-go-grpc
30-
run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
29+
- name: Login to DockerHub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
3134

3235
- name: Run GoReleaser
3336
uses: goreleaser/goreleaser-action@v5
3437
with:
35-
# either 'goreleaser' (default) or 'goreleaser-pro'
3638
distribution: goreleaser
3739
version: latest
3840
args: release --clean
3941
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
42-
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ builds:
1818
- CGO_ENABLED=0
1919
goos:
2020
- linux
21-
- windows
22-
- darwin
21+
goarch:
22+
- amd64
23+
- arm64
2324
main: ./cmd/dockersync
25+
binary: docker-sync
2426

2527
archives:
2628
- format: tar.gz
@@ -29,10 +31,6 @@ archives:
2931
{{- .Os }}_
3032
{{- .Arch }}
3133
{{- if .Arm }}v{{ .Arm }}{{ end }}
32-
# use zip for windows archives
33-
format_overrides:
34-
- goos: windows
35-
format: zip
3634
3735
changelog:
3836
sort: asc
@@ -46,4 +44,23 @@ release:
4644
owner: "Altinity"
4745
name: "docker-sync"
4846

49-
name_template: "{{.ProjectName}}-v{{.Version}}"
47+
name_template: "{{.ProjectName}}-v{{.Version}}"
48+
49+
dockers:
50+
- image_templates:
51+
- "altinity/docker-sync:{{.Version}}-amd64"
52+
use: buildx
53+
dockerfile: Dockerfile
54+
build_flag_templates:
55+
- "--platform linux/amd64"
56+
- image_templates:
57+
- "altinity/docker-sync:{{.Version}}-arm64v6"
58+
use: buildx
59+
dockerfile: Dockerfile
60+
build_flag_templates:
61+
- "--platform linux/arm64/v8"
62+
docker_manifests:
63+
- name_template: "altinity/docker-sync:{{.Version}}"
64+
image_templates:
65+
- "altinity/docker-sync:{{.Version}}-amd64"
66+
- "altinity/docker-sync:{{.Version}}-arm64v8"

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM scratch
2+
3+
COPY docker-sync /
4+
5+
EXPOSE 9090
6+
7+
ENTRYPOINT ["/docker-sync"]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
all:
2+
mkdir dist 2>/dev/null || true
3+
cd cmd/dockersync && go build -o ../../dist/dockersync
4+
echo "Binary is in dist/dockersync"

README.md

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,154 @@
11
# docker-sync
2-
Keep registries in sync
2+
3+
Simple tool to keep images in sync between different registries.
4+
5+
It uses the OCI distribution spec to pull and push images, so it should work with any compliant registry.
6+
7+
Currently, it doesn't support the deprecated v1 manifests, and there are no plans to support them.
8+
9+
## Usage
10+
11+
Clone the repository:
12+
13+
```console
14+
git clone https://github.com/Altinity/docker-sync.git
15+
```
16+
17+
Change to the project directory:
18+
19+
```console
20+
cd docker-sync
21+
```
22+
23+
Build the project:
24+
25+
```console
26+
make
27+
```
28+
29+
Write the default config file:
30+
31+
```console
32+
dist/dockersync writeConfig -o config.yaml`
33+
```
34+
35+
Edit the config file accordingly, then run:
36+
37+
```console
38+
dist/dockersync
39+
```
40+
41+
## Configuration
42+
43+
The default configuration looks like this:
44+
45+
```yaml
46+
ecr:
47+
region: us-east-1
48+
logging:
49+
colors: true
50+
format: text
51+
level: INFO
52+
output: stdout
53+
timeformat: "15:04:05"
54+
sync:
55+
images:
56+
- source: docker.io/library/ubuntu
57+
targets:
58+
- docker.io/kamushadenes/ubuntu
59+
interval: 5m
60+
maxerrors: 5
61+
registries:
62+
- auth:
63+
helper: ""
64+
password: ""
65+
token: ""
66+
username: ""
67+
name: Docker Hub
68+
url: docker.io
69+
telemetry:
70+
enabled: false
71+
metrics:
72+
exporter: prometheus
73+
prometheus:
74+
address: 127.0.0.1:9090
75+
path: /metrics
76+
stdout:
77+
interval: 5s
78+
```
79+
80+
The `sync` section is where you define the images you want to keep in sync. The `interval` is the time between syncs, and `maxerrors` is the maximum number of errors before the sync is stopped and the program exits.
81+
82+
### Authentication
83+
84+
To provide authentication for registries, put them under `sync.registries` in the following format:
85+
86+
```yaml
87+
sync:
88+
registries:
89+
- auth:
90+
helper: ""
91+
password: ""
92+
token: ""
93+
username: ""
94+
name: Docker Hub
95+
url: docker.io
96+
```
97+
98+
#### ECR
99+
100+
To authenticate against ECR, you can leave `password`, `token` and `username` empty, and set `helper` to `ecr`:
101+
102+
```yaml
103+
sync:
104+
registries:
105+
- auth:
106+
helper: ecr
107+
password: ""
108+
token: ""
109+
username: ""
110+
name: ECR
111+
url: 123456789012.dkr.ecr.us-east-1.amazonaws.com
112+
```
113+
114+
The same applies to ecr-public, since it uses the url prefix to differentiate between the two.
115+
116+
Now, any image under `123456789012.dkr.ecr.us-east-1.amazonaws.com` will be authenticated using the default AWS credentials.
117+
118+
#### GCR
119+
120+
To authenticate against ECR, get either a access token or service account key.
121+
122+
##### Access Token
123+
124+
Check the [GCR documentation](https://cloud.google.com/artifact-registry/docs/docker/authentication#token) for more information.
125+
126+
Note that access tokens are short lived.
127+
128+
```yaml
129+
sync:
130+
registries:
131+
- auth:
132+
helper: ""
133+
password: "PASSWORD"
134+
token: ""
135+
username: "oauth2accesstoken"
136+
name: GCR / GAR
137+
url: gcr.io
138+
```
139+
140+
##### Service Account Key
141+
142+
Check the [GCR documentation](https://cloud.google.com/artifact-registry/docs/docker/authentication#json-key) for more information.
143+
144+
```yaml
145+
sync:
146+
registries:
147+
- auth:
148+
helper: ""
149+
password: "BASE64_ENCODED_JSON_KEY"
150+
token: ""
151+
username: "_json_key_base64"
152+
name: GCR / GAR
153+
url: gcr.io
154+
```

cmd/dockersync/config.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

config/keys.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,20 @@ var (
5858
WithValidDuration())
5959
// endregion
6060

61-
// region Repositories
61+
// region Sync
6262

63-
// Repositories specifies the repositories to use for pulling and pushing images.
64-
Repositories = NewKey("repositories",
63+
// SyncMaxErrors specifies the maximum number of errors that can occur before the application exits.
64+
SyncMaxErrors = NewKey("sync.maxErrors",
65+
WithDefaultValue(5),
66+
WithValidInt())
67+
68+
// SyncInterval specifies the interval at which images are synchronized.
69+
SyncInterval = NewKey("sync.interval",
70+
WithDefaultValue("5m"),
71+
WithValidDuration())
72+
73+
// SyncRegistries specifies the repositories to use for pulling and pushing images.
74+
SyncRegistries = NewKey("sync.registries",
6575
WithDefaultValue([]map[string]interface{}{
6676
{
6777
"name": "Docker Hub",
@@ -70,22 +80,19 @@ var (
7080
"username": "",
7181
"password": "",
7282
"token": "",
73-
"helper": "docker-credential-desktop",
83+
"helper": "",
7484
},
7585
},
7686
}),
7787
WithValidRepositories())
78-
// endregion
79-
80-
// region Images
8188

82-
// Images specifies the images to synchronize.
83-
Images = NewKey("images",
89+
// SyncImages specifies the images to synchronize.
90+
SyncImages = NewKey("sync.images",
8491
WithDefaultValue([]map[string]interface{}{
8592
{
8693
"source": "docker.io/library/ubuntu",
8794
"targets": []string{
88-
"docker.io/library/ubuntu:latest",
95+
"docker.io/library/ubuntu",
8996
},
9097
},
9198
}),

0 commit comments

Comments
 (0)