mirror of
https://github.com/h44z/wg-portal.git
synced 2025-08-13 16:52:24 +00:00
Compare commits
5 Commits
v2.1.0-bet
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
41cab5f7ea | ||
|
708c558211 | ||
|
99df4ca3cd | ||
|
9884d8c002 | ||
|
b099e8abfa |
4
.github/workflows/chart.yml
vendored
4
.github/workflows/chart.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- uses: docker/login-action@v3
|
- uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
|
8
.github/workflows/docker-publish.yml
vendored
8
.github/workflows/docker-publish.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
@ -66,10 +66,6 @@ jobs:
|
|||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
type=semver,pattern=v{{major}}.{{minor}}
|
type=semver,pattern=v{{major}}.{{minor}}
|
||||||
type=semver,pattern=v{{major}}
|
type=semver,pattern=v{{major}}
|
||||||
# add v{{major}} tag, even for beta or release-canidate releases
|
|
||||||
type=match,pattern=(v\d),group=1,enable=${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
|
||||||
# add {{major}} tag, even for beta releases or release-canidate releases
|
|
||||||
type=match,pattern=v(\d),group=1,enable=${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
@ -114,7 +110,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Download binaries
|
- name: Download binaries
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
name: binaries
|
name: binaries
|
||||||
|
|
||||||
|
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/coreos/go-oidc/v3 v3.15.0
|
github.com/coreos/go-oidc/v3 v3.15.0
|
||||||
github.com/glebarez/sqlite v1.11.0
|
github.com/glebarez/sqlite v1.11.0
|
||||||
github.com/go-ldap/ldap/v3 v3.4.11
|
github.com/go-ldap/ldap/v3 v3.4.11
|
||||||
github.com/go-pkgz/routegroup v1.5.1
|
github.com/go-pkgz/routegroup v1.5.2
|
||||||
github.com/go-playground/validator/v10 v10.27.0
|
github.com/go-playground/validator/v10 v10.27.0
|
||||||
github.com/go-webauthn/webauthn v0.13.4
|
github.com/go-webauthn/webauthn v0.13.4
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
4
go.sum
4
go.sum
@ -70,8 +70,8 @@ github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9Z
|
|||||||
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
||||||
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
|
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
|
||||||
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
|
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
|
||||||
github.com/go-pkgz/routegroup v1.5.1 h1:hwVU4w2ltMQXIGEM4WIM0aWyRn7FsZbfbZIlPH7f1Rk=
|
github.com/go-pkgz/routegroup v1.5.2 h1:/W/5GwsHaojeEBldiSB/fcqPLm0AE/eT36reCsMEbtY=
|
||||||
github.com/go-pkgz/routegroup v1.5.1/go.mod h1:kDDPDRLRiRY1vnENrZJw1jQAzQX7fvsbsHGRQFNQfKc=
|
github.com/go-pkgz/routegroup v1.5.2/go.mod h1:Pmu04fhgWhRtBMIJ8HXppnnzOPjnL/IEPBIdO2zmeqg=
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
@ -47,11 +47,18 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
|
|||||||
}
|
}
|
||||||
latestVersion := "1.0.9"
|
latestVersion := "1.0.9"
|
||||||
if lastVersion.Version != latestVersion {
|
if lastVersion.Version != latestVersion {
|
||||||
return fmt.Errorf("unsupported old version, update to database version %s first: %w", latestVersion, err)
|
return fmt.Errorf("unsupported old version, update to database version %s first", latestVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("found valid V1 database", "version", lastVersion.Version)
|
slog.Info("found valid V1 database", "version", lastVersion.Version)
|
||||||
|
|
||||||
|
// validate target database
|
||||||
|
if err := validateTargetDatabase(db); err != nil {
|
||||||
|
return fmt.Errorf("target database validation failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("found valid target database, starting migration...")
|
||||||
|
|
||||||
if err := migrateV1Users(oldDb, db); err != nil {
|
if err := migrateV1Users(oldDb, db); err != nil {
|
||||||
return fmt.Errorf("user migration failed: %w", err)
|
return fmt.Errorf("user migration failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -70,6 +77,36 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validateTargetDatabase checks if the target database is empty and ready for migration.
|
||||||
|
func validateTargetDatabase(db *gorm.DB) error {
|
||||||
|
var count int64
|
||||||
|
err := db.Model(&domain.User{}).Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to check user table: %w", err)
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return fmt.Errorf("target database contains %d users, please use an empty database for migration", count)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Model(&domain.Interface{}).Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to check interface table: %w", err)
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return fmt.Errorf("target database contains %d interfaces, please use an empty database for migration", count)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Model(&domain.Peer{}).Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to check peer table: %w", err)
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return fmt.Errorf("target database contains %d peers, please use an empty database for migration", count)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func migrateV1Users(oldDb, newDb *gorm.DB) error {
|
func migrateV1Users(oldDb, newDb *gorm.DB) error {
|
||||||
type User struct {
|
type User struct {
|
||||||
Email string `gorm:"primaryKey"`
|
Email string `gorm:"primaryKey"`
|
||||||
@ -123,7 +160,7 @@ func migrateV1Users(oldDb, newDb *gorm.DB) error {
|
|||||||
LinkedPeerCount: 0,
|
LinkedPeerCount: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := newDb.Save(&newUser).Error; err != nil {
|
if err := newDb.Create(&newUser).Error; err != nil {
|
||||||
return fmt.Errorf("failed to migrate user %s: %w", oldUser.Email, err)
|
return fmt.Errorf("failed to migrate user %s: %w", oldUser.Email, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +254,8 @@ func migrateV1Interfaces(oldDb, newDb *gorm.DB) error {
|
|||||||
PeerDefPostDown: "",
|
PeerDefPostDown: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := newDb.Save(&newInterface).Error; err != nil {
|
// Create new interface with associations
|
||||||
|
if err := newDb.Create(&newInterface).Error; err != nil {
|
||||||
return fmt.Errorf("failed to migrate device %s: %w", oldDevice.DeviceName, err)
|
return fmt.Errorf("failed to migrate device %s: %w", oldDevice.DeviceName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +400,7 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := newDb.Save(&newPeer).Error; err != nil {
|
if err := newDb.Create(&newPeer).Error; err != nil {
|
||||||
return fmt.Errorf("failed to migrate peer %s (%s): %w", oldPeer.Identifier, oldPeer.PublicKey, err)
|
return fmt.Errorf("failed to migrate peer %s (%s): %w", oldPeer.Identifier, oldPeer.PublicKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +225,15 @@ func (m Manager) RestoreInterfaceState(
|
|||||||
if err != nil && !iface.IsDisabled() {
|
if err != nil && !iface.IsDisabled() {
|
||||||
slog.Debug("creating missing interface", "interface", iface.Identifier)
|
slog.Debug("creating missing interface", "interface", iface.Identifier)
|
||||||
|
|
||||||
|
// temporarily disable interface in database so that the current state is reflected correctly
|
||||||
|
_ = m.db.SaveInterface(ctx, iface.Identifier,
|
||||||
|
func(in *domain.Interface) (*domain.Interface, error) {
|
||||||
|
now := time.Now()
|
||||||
|
in.Disabled = &now // set
|
||||||
|
in.DisabledReason = domain.DisabledReasonInterfaceMissing
|
||||||
|
return in, nil
|
||||||
|
})
|
||||||
|
|
||||||
// try to create a new interface
|
// try to create a new interface
|
||||||
_, err = m.saveInterface(ctx, &iface)
|
_, err = m.saveInterface(ctx, &iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user