-
Notifications
You must be signed in to change notification settings - Fork 117
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 #328 from sgotti/replace_datamanager_with_sql
*: replace etcd and datamanager with a sql db
- Loading branch information
Showing
141 changed files
with
14,099 additions
and
15,450 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
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
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,96 @@ | ||
// Copyright 2022 Sorint.lab | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"agola.io/agola/internal/errors" | ||
"agola.io/agola/internal/migration" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var cmdMigrate = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "migrate from an old data format export to the new data format", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := migrate(cmd, args); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
}, | ||
} | ||
|
||
type migrateOptions struct { | ||
serviceName string | ||
inFilePath string | ||
outFilePath string | ||
} | ||
|
||
var migrateOpts migrateOptions | ||
|
||
func init() { | ||
flags := cmdMigrate.Flags() | ||
|
||
flags.StringVar(&migrateOpts.serviceName, "service", "", "service name (runservice or configstore)") | ||
flags.StringVar(&migrateOpts.inFilePath, "in", "-", "input file path") | ||
flags.StringVar(&migrateOpts.outFilePath, "out", "-", "output file path") | ||
|
||
cmdAgola.AddCommand(cmdMigrate) | ||
} | ||
|
||
func migrate(cmd *cobra.Command, args []string) error { | ||
if migrateOpts.serviceName != "runservice" && migrateOpts.serviceName != "configstore" { | ||
return errors.Errorf("service option must be runservice or configstore") | ||
} | ||
|
||
var r *os.File | ||
if migrateOpts.inFilePath == "-" { | ||
r = os.Stdin | ||
} else { | ||
var err error | ||
r, err = os.Open(migrateOpts.inFilePath) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
} | ||
|
||
var w *os.File | ||
if migrateOpts.outFilePath == "-" { | ||
w = os.Stdout | ||
} else { | ||
var err error | ||
w, err = os.Create(migrateOpts.outFilePath) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
} | ||
|
||
log.Info().Msgf("migrating %s", migrateOpts.serviceName) | ||
switch migrateOpts.serviceName { | ||
case "runservice": | ||
if err := migration.MigrateRunService(context.Background(), r, w); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
case "configstore": | ||
if err := migration.MigrateConfigStore(context.Background(), r, w); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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
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,44 @@ | ||
## Migrating from v0.7.x | ||
|
||
Agola versions after v0.7.x moved their internal db based on etcd and objectstorage to a standard external sql database (PostgreSQL or sqlite for single node deployments). | ||
|
||
If you are going to update from a version <= v0.7.x you should do some manual steps to migrate the runservice and configstore data. | ||
|
||
We suggest to test this migration on a test environment before doing this on your primary environment and keep backups. | ||
|
||
1. Ensure you're using or update to the latest v0.7.x | ||
1. Place somewhere the new agola > v0.7.x binary. In the next steps it'll be places in `/tmp` | ||
1. Keep only the runservice and configstore services active. Stop the agola gateway to avoid external activity that will be lost by the backups taken in the next steps. | ||
1. Take runservice and configstore backups | ||
|
||
`curl -v http://$RUNSERVICEHOST:PORT/api/v1alpha/export > /tmp/runservice-export` | ||
|
||
`curl -v http://$CONFIGSTOREHOST:PORT/api/v1alpha/export > /tmp/configstore-export` | ||
|
||
1. Generate the migrated data using the new agola binary migrate command: | ||
|
||
`cat /tmp/runservice-export | ./tmp/agola migrate --service runservice > /tmp/runservice-migrated` | ||
|
||
`cat /tmp/runservice-export | ./tmp/agola migrate --service configstore > /tmp/configstore-migrated` | ||
|
||
1. Update the agola binaries on your environment or use a test enviroment and start only the runservice and configstore. | ||
1. Update the agola config file and remove the runservice, configstore, notification service etcd entries and add the db entries. Every component should have its own dedicated database. DO NOT use the same database for all the services. For PostgresSQL it can be the same postgres instance but with different databases. | ||
1. Put the runservice and configstore in maintenance mode | ||
|
||
`curl -v -XPUT http://$NEWRUNSERVICEHOST:PORT/api/v1alpha/maintenance` | ||
|
||
`curl -v -XPUT http://$NEWCONFIGSTOREHOST:PORT/api/v1alpha/maintenance` | ||
|
||
1. Import the migrated data | ||
|
||
`cat /tmp/runservice-migrated | curl -v -d @- http://$NEWRUNSERVICEHOST:PORT/api/v1alpha/import` | ||
|
||
`cat /tmp/configstore-migrated | curl -v -d @- http://$NEWCONFIGSTOREHOST:PORT/api/v1alpha/import` | ||
|
||
1. Put the runservice and configstore in maintenance mode | ||
|
||
`curl -v -XDELETE http://$NEWRUNSERVICEHOST:PORT/api/v1alpha/maintenance` | ||
|
||
`curl -v -XDELETE http://$NEWCONFIGSTOREHOST:PORT/api/v1alpha/maintenance` | ||
|
||
1. Start the gateway and test if the migration was successfull |
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
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.