Commit 9f9d0c8f authored by Konstantinos Samaras-Tsakiris's avatar Konstantinos Samaras-Tsakiris
Browse files

Merge branch 'fix-clone-db' into 'master'

Made DB procedure more flexible to use paths

See merge request !134
parents 425e1b90 f9d3d214
Pipeline #3306690 passed with stages
in 4 minutes and 25 seconds
......@@ -730,7 +730,8 @@ func (r *DrupalSiteReconciler) updateDBSchema(ctx context.Context, d *webservice
// Take backup
backupFileName := "db_backup_update_rollback.sql"
if _, err := r.execToServerPodErrOnStderr(ctx, d, "php-fpm", nil, takeBackup(backupFileName)...); err != nil {
// We set Backup on "Drupal-data" so the DB backup is stored on the PV of the website
if _, err := r.execToServerPodErrOnStderr(ctx, d, "php-fpm", nil, takeBackup("/drupal-data/"+backupFileName)...); err != nil {
setConditionStatus(d, "DBUpdatesFailed", true, newApplicationError(err, ErrPodExec), false)
return true
}
......
......@@ -1631,6 +1631,8 @@ func jobForDrupalSiteInstallation(currentobject *batchv1.Job, databaseSecret str
// jobForDrupalSiteClone returns a job object thats clones a drupalsite
func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d *webservicesv1a1.DrupalSite) error {
ls := labelsForDrupalSite(d.Name)
// Temporary folder to store ephemeral files used during cloning procedure
var emptyDir = "/var/empty-run/"
if currentobject.CreationTimestamp.IsZero() {
addOwnerRefToObject(currentobject, asOwner(d))
currentobject.Labels = map[string]string{}
......@@ -1643,7 +1645,7 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d
Image: sitebuilderImageRefToUse(d, releaseID(d)).Name,
Name: "src-db-backup",
ImagePullPolicy: "Always",
Command: takeBackup("dbBackUp.sql"),
Command: takeBackup(emptyDir + "dbBackUp.sql"),
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(jobMemoryRequest),
......@@ -1664,10 +1666,13 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d
},
},
},
VolumeMounts: []corev1.VolumeMount{{
Name: "drupal-directory-" + string(d.Spec.Configuration.CloneFrom),
MountPath: "/drupal-data",
}},
VolumeMounts: []corev1.VolumeMount{
{
Name: "tmp-dir",
MountPath: emptyDir,
},
},
},
},
RestartPolicy: "Never",
......@@ -1675,7 +1680,7 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d
Image: sitebuilderImageRefToUse(d, releaseID(d)).Name,
Name: "dest-clone",
ImagePullPolicy: "Always",
Command: cloneSource("dbBackUp.sql"),
Command: cloneSource(emptyDir + "dbBackUp.sql"),
Env: []corev1.EnvVar{
{
Name: "DRUPAL_SHARED_VOLUME",
......@@ -1719,6 +1724,10 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d
SubPath: "settings.php",
ReadOnly: true,
},
{
Name: "tmp-dir",
MountPath: emptyDir,
},
},
}},
Volumes: []corev1.Volume{
......@@ -1758,6 +1767,11 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d
},
},
},
{
// Tmp Dir storage to address issue https://gitlab.cern.ch/webservices/webframeworks-planning/-/issues/692
Name: "tmp-dir",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
},
},
}
ls["app"] = "clone"
......@@ -2036,8 +2050,8 @@ func runUpDBCommand() []string {
}
// takeBackup outputs the command need to take the database backup to a given filename
func takeBackup(filename string) []string {
return []string{"/operations/database-backup.sh", "-f", filename}
func takeBackup(filepath string) []string {
return []string{"/operations/database-backup.sh", "-p", filepath}
}
// restoreBackup outputs the command need to restore the database backup from a given filename
......@@ -2046,8 +2060,8 @@ func restoreBackup(filename string) []string {
}
// cloneSource outputs the command need to clone a drupal site
func cloneSource(filename string) []string {
return []string{"/operations/clone.sh", "-f", filename}
func cloneSource(filepath string) []string {
return []string{"/operations/clone.sh", "-p", filepath}
}
// encryptBasicAuthPassword encrypts a password for basic authentication
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment