Skip to content

Commit 48314cf

Browse files
authored
feat: add Docker support (#861)
1 parent 4944c01 commit 48314cf

File tree

9 files changed

+184
-482
lines changed

9 files changed

+184
-482
lines changed

.github/workflows/docker-publish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Docker Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata for Docker
33+
id: meta
34+
uses: docker/metadata-action@v4
35+
with:
36+
images: ghcr.io/${{ github.repository }}
37+
tags: |
38+
type=semver,pattern={{version}}
39+
type=raw,value=latest
40+
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@v6
43+
with:
44+
platforms: linux/amd64,linux/arm64
45+
push: true
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.21-alpine AS builder
2+
WORKDIR /app
3+
COPY . .
4+
RUN go mod download
5+
RUN go build -o redis-shake ./cmd/redis-shake
6+
7+
FROM alpine:latest
8+
WORKDIR /app
9+
COPY --from=builder /app/redis-shake .
10+
COPY shake_sync_env.toml .
11+
COPY shake_scan_env.toml .
12+
COPY entrypoint.sh .
13+
14+
RUN chmod +x entrypoint.sh
15+
16+
ENTRYPOINT ["/bin/sh", "entrypoint.sh"]

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@ RedisShake is a tool designed for processing and migrating Redis data. It offers
3939

4040
Download the binary package directly from the [Releases](https://github.com/tair-opensource/RedisShake/releases) page.
4141

42+
#### Docker
43+
44+
```shell
45+
docker run --network host \
46+
-e SYNC=true \
47+
-e SHAKE_SRC_ADDRESS=127.0.0.1:6379 \
48+
-e SHAKE_DST_ADDRESS=127.0.0.1:6380 \
49+
ghcr.io/tair-opensource/redisshake:latest
50+
```
51+
4252
#### Compile from Source
4353

4454
To compile from source, ensure that you have a Golang environment set up on your local machine:
4555

4656
```shell
47-
git clone https://github.com/alibaba/RedisShake
57+
git clone https://github.com/tair-opensource/RedisShake
4858
cd RedisShake
4959
sh build.sh
5060
```

entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
if [ "$SYNC" = "true" ]; then
3+
./redis-shake shake_sync_env.toml
4+
elif [ "$SCAN" = "true" ]; then
5+
./redis-shake shake_scan_env.toml
6+
else
7+
echo "Error: Neither SYNC nor SCAN environment variable is set to true"
8+
exit 1
9+
fi

go.mod

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ require (
88
github.com/gofrs/flock v0.8.1
99
github.com/mcuadros/go-defaults v1.2.0
1010
github.com/rs/zerolog v1.28.0
11-
github.com/spf13/viper v1.15.0
11+
github.com/spf13/viper v1.18.1
1212
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
1313
)
1414

1515
require (
16-
github.com/fsnotify/fsnotify v1.6.0 // indirect
16+
github.com/a8m/envsubst v1.4.2 // indirect
17+
github.com/fsnotify/fsnotify v1.7.0 // indirect
1718
github.com/hashicorp/hcl v1.0.0 // indirect
1819
github.com/magiconair/properties v1.8.7 // indirect
19-
github.com/mattn/go-colorable v0.1.12 // indirect
20-
github.com/mattn/go-isatty v0.0.14 // indirect
20+
github.com/mattn/go-colorable v0.1.13 // indirect
21+
github.com/mattn/go-isatty v0.0.17 // indirect
2122
github.com/mitchellh/mapstructure v1.5.0 // indirect
22-
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
23-
github.com/spf13/afero v1.9.3 // indirect
24-
github.com/spf13/cast v1.5.0 // indirect
25-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
23+
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
24+
github.com/sagikazarmark/locafero v0.4.0 // indirect
25+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
26+
github.com/sourcegraph/conc v0.3.0 // indirect
27+
github.com/spf13/afero v1.11.0 // indirect
28+
github.com/spf13/cast v1.6.0 // indirect
2629
github.com/spf13/pflag v1.0.5 // indirect
27-
github.com/subosito/gotenv v1.4.2 // indirect
28-
golang.org/x/sys v0.12.0 // indirect
29-
golang.org/x/text v0.12.0 // indirect
30+
github.com/subosito/gotenv v1.6.0 // indirect
31+
go.uber.org/atomic v1.9.0 // indirect
32+
go.uber.org/multierr v1.9.0 // indirect
33+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
34+
golang.org/x/sys v0.15.0 // indirect
35+
golang.org/x/text v0.14.0 // indirect
3036
gopkg.in/ini.v1 v1.67.0 // indirect
3137
gopkg.in/yaml.v3 v3.0.1 // indirect
3238
)

go.sum

Lines changed: 51 additions & 451 deletions
Large diffs are not rendered by default.

internal/config/config.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package config
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
67
"strings"
78

89
"RedisShake/internal/log"
910

11+
"github.com/a8m/envsubst"
1012
"github.com/mcuadros/go-defaults"
1113
"github.com/rs/zerolog"
1214
"github.com/spf13/viper"
1315
)
1416

1517
type FilterOptions struct {
16-
AllowKeyPrefix []string `mapstructure:"allow_key_prefix" default:"[]"`
17-
AllowKeySuffix []string `mapstructure:"allow_key_suffix" default:"[]"`
18-
BlockKeyPrefix []string `mapstructure:"block_key_prefix" default:"[]"`
19-
BlockKeySuffix []string `mapstructure:"block_key_suffix" default:"[]"`
20-
AllowDB []int `mapstructure:"allow_db" default:"[]"`
21-
BlockDB []int `mapstructure:"block_db" default:"[]"`
22-
AllowCommand []string `mapstructure:"allow_command" default:"[]"`
23-
BlockCommand []string `mapstructure:"block_command" default:"[]"`
18+
AllowKeyPrefix []string `mapstructure:"allow_key_prefix" default:"[]"`
19+
AllowKeySuffix []string `mapstructure:"allow_key_suffix" default:"[]"`
20+
BlockKeyPrefix []string `mapstructure:"block_key_prefix" default:"[]"`
21+
BlockKeySuffix []string `mapstructure:"block_key_suffix" default:"[]"`
22+
AllowDB []int `mapstructure:"allow_db" default:"[]"`
23+
BlockDB []int `mapstructure:"block_db" default:"[]"`
24+
AllowCommand []string `mapstructure:"allow_command" default:"[]"`
25+
BlockCommand []string `mapstructure:"block_command" default:"[]"`
2426
AllowCommandGroup []string `mapstructure:"allow_command_group" default:"[]"`
2527
BlockCommandGroup []string `mapstructure:"block_command_group" default:"[]"`
2628
Function string `mapstructure:"function" default:""`
@@ -73,7 +75,7 @@ func (opt *AdvancedOptions) GetPSyncCommand(address string) string {
7375
}
7476

7577
type ShakeOptions struct {
76-
Filter FilterOptions
78+
Filter FilterOptions
7779
Advanced AdvancedOptions
7880
Module ModuleOptions
7981
}
@@ -97,18 +99,20 @@ func LoadConfig() *viper.Viper {
9799
if len(os.Args) == 2 {
98100
logger.Info().Msgf("load config from file: %s", os.Args[1])
99101
configFile := os.Args[1]
100-
v.SetConfigFile(configFile)
101-
err := v.ReadInConfig()
102+
buf, err := envsubst.ReadFile(configFile)
102103
if err != nil {
103-
panic(err)
104+
logger.Error().Msgf("failed to read config file: %v", err)
105+
os.Exit(1)
104106
}
105-
}
106-
107-
// load config from environment variables
108-
if len(os.Args) == 1 {
109-
logger.Warn().Msg("load config from environment variables")
110-
v.SetConfigType("env")
111-
v.AutomaticEnv()
107+
v.SetConfigType("toml")
108+
err = v.ReadConfig(bytes.NewReader(buf))
109+
if err != nil {
110+
logger.Error().Msgf("failed to read config file: %v", err)
111+
os.Exit(1)
112+
}
113+
} else {
114+
logger.Error().Msg("config file not found")
115+
os.Exit(1)
112116
}
113117

114118
// unmarshal config

shake_scan_env.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[scan_reader]
2+
address = "${SHAKE_SRC_ADDRESS}" # export SHAKE_SRC_ADDRESS=127.0.0.1:6379
3+
4+
[redis_writer]
5+
address = "${SHAKE_DST_ADDRESS}" # export SHAKE_DST_ADDRESS=127.0.0.1:6380

shake_sync_env.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[sync_reader]
2+
address = "${SHAKE_SRC_ADDRESS}" # export SHAKE_SRC_ADDRESS=127.0.0.1:6379
3+
4+
[redis_writer]
5+
address = "${SHAKE_DST_ADDRESS}" # export SHAKE_DST_ADDRESS=127.0.0.1:6380

0 commit comments

Comments
 (0)