Skip to content

Commit a062961

Browse files
committed
tool
1 parent 80e469f commit a062961

7 files changed

Lines changed: 439 additions & 0 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
config.yaml
2+
.git
3+
.github
4+
*.md
5+
LICENSE
6+
.env
7+
.DS_Store

.github/workflows/build.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: build docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
env:
13+
IMAGE: govdbot/govd:${{ github.ref_name }}
14+
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref_name }}
15+
16+
jobs:
17+
build-images:
18+
strategy:
19+
matrix:
20+
arch: [amd64, arm64]
21+
include:
22+
- arch: amd64
23+
platform: linux/amd64
24+
runner: ubuntu-24.04
25+
- arch: arm64
26+
platform: linux/arm64
27+
runner: ubuntu-24.04-arm
28+
runs-on: ${{ matrix.runner }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Login to Docker Hub
37+
uses: docker/login-action@v3
38+
with:
39+
username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Login to GitHub Container Registry
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ghcr.io
46+
username: ${{ github.repository_owner }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Build and push ${{ matrix.arch }} image
50+
uses: docker/build-push-action@v6
51+
with:
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max
54+
context: .
55+
platforms: ${{ matrix.platform }}
56+
push: true
57+
file: ./Dockerfile
58+
tags: |
59+
${{ env.IMAGE }}-${{ matrix.arch }}
60+
${{ env.GHCR_IMAGE }}-${{ matrix.arch }}
61+
62+
push-manifest:
63+
needs: [build-images]
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Login to Docker Hub
67+
uses: docker/login-action@v3
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
72+
- name: Login to GitHub Container Registry
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.repository_owner }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Create tagged manifest
80+
uses: int128/docker-manifest-create-action@v2
81+
with:
82+
tags: ${{ env.IMAGE }}
83+
sources: |
84+
${{ env.IMAGE }}-amd64
85+
${{ env.IMAGE }}-arm64
86+
87+
- name: Create tagged manifest for GitHub
88+
uses: int128/docker-manifest-create-action@v2
89+
with:
90+
tags: ${{ env.GHCR_IMAGE }}
91+
sources: |
92+
${{ env.GHCR_IMAGE }}-amd64
93+
${{ env.GHCR_IMAGE }}-arm64

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Build stage
2+
FROM golang:1.24-alpine AS builder
3+
4+
RUN apk add --no-cache git ca-certificates tzdata
5+
6+
WORKDIR /app
7+
8+
COPY go.mod go.sum* ./
9+
10+
RUN go mod download
11+
12+
COPY . .
13+
14+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o migrate .
15+
16+
FROM alpine:latest
17+
18+
RUN apk --no-cache add ca-certificates tzdata
19+
20+
WORKDIR /root/
21+
22+
COPY --from=builder /app/migrate .
23+
24+
CMD ["./migrate"]

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# govd migration tool
2+
this utility helps you migrate your govd users from v1 (MySQL) to v2 (PostgreSQL).
3+
4+
## run
5+
make sure you have Docker installed and both the source (MySQL) and target (PostgreSQL) databases running and accessible (exposed or shared network), then run:
6+
7+
```bash
8+
docker run --rm \
9+
-e V1_DSN='govd:password@tcp(db_v1:3306)/govd?charset=utf8mb4&parseTime=True&loc=Local' \
10+
-e V2_DSN='postgres://govd:password@db_v2:5432/govd?sslmode=disable' \
11+
govdbot/migrate:latest
12+
```

go.mod

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module github.com/govdbot/migrate
2+
3+
go 1.24.0
4+
5+
toolchain go1.24.2
6+
7+
require (
8+
github.com/jackc/pgx/v5 v5.7.1
9+
gorm.io/driver/mysql v1.6.0
10+
gorm.io/gorm v1.31.1
11+
)
12+
13+
require (
14+
filippo.io/edwards25519 v1.1.0 // indirect
15+
github.com/go-sql-driver/mysql v1.9.3 // indirect
16+
github.com/jackc/pgpassfile v1.0.0 // indirect
17+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
18+
github.com/jackc/puddle/v2 v2.2.2 // indirect
19+
github.com/jinzhu/inflection v1.0.0 // indirect
20+
github.com/jinzhu/now v1.1.5 // indirect
21+
golang.org/x/crypto v0.27.0 // indirect
22+
golang.org/x/sync v0.9.0 // indirect
23+
golang.org/x/text v0.20.0 // indirect
24+
)

go.sum

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
2+
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
7+
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
8+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
9+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
10+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
11+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
12+
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
13+
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
14+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
15+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
16+
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
17+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
18+
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
19+
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
20+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
21+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
22+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
23+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
24+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
25+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
26+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
27+
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
28+
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
29+
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
30+
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
31+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
32+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
33+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
34+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
35+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
36+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
37+
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
38+
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
39+
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
40+
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=

0 commit comments

Comments
 (0)