Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] backup/restore jobs directory #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kwmonroe
Copy link

Include actions that allow a user to backup and restore the jenkins job dir. Usage details can be found in the additions to README.md, but the basics are:

## backup
$ juju run-action jenkins/0 backup-jobs
...
fetchcmd = juju scp jenkins/0:<path> .
...
$ juju scp jenkins/0:/home/ubuntu/jobs-x.tgz .

## restore
$ juju attach jenkins jobs=./jobs-x.tgz
$ juju run-action jenkins/0 restore-jobs

One potential point of contention may be the requirement for users to attach a resource to be used during restore-jobs. I considered having a url parameter that the action would fetch. However, given the multitude of url patterns and problems accessing a random url in a restricted network deployment, I decided that attaching a local file would give the best UX.

If merged, this means that all future charm release jenkins activity would need to include a jobs resource, e.g.:

## create a dummy jobs resource placeholder
$ touch /tmp/jobs.tgz
$ charm push <dir> <cs> --resource jobs=/tmp/jobs.tgz

## all subsequent releases can use 'jobs-0', no need to touch/attach new placeholders
$ charm release <cs> --resource jobs-0

The above is simply attaching a 0-byte resource to the charm, which will be handled correctly by the restore action (i.e., it will fail gracefully if anyone attempts to restore jobs using the default resource).

Note, there may very well be a jenkins plugin that already provides this functionality, but from my limited research, it seems most online tutorials walk a user through backing up / restoring the jobs directory manually. This PR, then, simply action-ifies that process. It's also handy to backup/restore without needing to click through the web interface.

* support snapshot/restore actions
* include resource metadata (required for restore-workspace action)
* support online and overwrite action options
  - allow the user to backup/restore while jenkins is running
  - allow the user to overwrite (vs update) existing data in the jobs dir
@jamesbeedy
Copy link
Contributor

jamesbeedy commented Mar 13, 2017

+1 can we get this bad boy merged? @kwmonroe nice work!

@freeekanayaka
Copy link
Collaborator

I didn't look at the code, but using a resource for the does indeed seem weird to me. Is this a pattern that is being used in other charms too? Have you considered bringing this use case to the attention of the juju team and asking their take?

Also, doesn't the Jenkins API already have a way to perform a backup and restore it? (genuine question, I don't know)

@kwmonroe
Copy link
Author

Hey @freeekanayaka -- the resource-before-action pattern is used by the ~containers team (that's where i got the idea in the first place). It makes more sense when you consider the restricted network env, where it's easier for an operator to attach something from their local system vs having the charm fetch something from a remote system.

It also opens the door for the reactive jenkins code to add a handler to support a jobs-on-install workflow based on a given resource. IOW, setup an entire jenkins jobs dir at deployment:

juju deploy jenkins jobs=~/my/jobs/dir.tgz

Have you considered bringing this use case to the attention of the juju team and asking their take?

No, but I don't really know what you're asking here. I don't see juju-core caring one way or another how this gets implemented. Fwiw, I've released a charm with these bits here:

https://jujucharms.com/u/juju-solutions/jenkins/3

It's been running nicely as the backbone for my big data charm ci system. I of course don't intend to maintain this for long -- I'm only mentioning it so people that want to kick tires don't have to pull down and build this locally.

Lmk if there's anything else I can clarify to guide the go/no-go decision on merging this. Thanks!

@freeekanayaka
Copy link
Collaborator

freeekanayaka commented Mar 23, 2017 via email

@stub42
Copy link
Contributor

stub42 commented Sep 25, 2019

The juju team is updating actions, and the design document includes support for input files. However, it doesn't exist yet and won't be backported, so we will need to use resources or 'juju scp'. Resources provides an arguably nicer UI, but 'juju scp' avoids stuffing the files onto the controller (I don't think it is a problem here, but is certainly a problem for actions wanting to restore potentially huge database dumps or files containing secrets for example).

I don't like the idea of requiring the operator to tunnel through to the REST API and make use of it, because it would require the operator to install and maintain additional scripts in their local environment to make the backups. This would be a pain to manage, keeping the client tools in sync with the deployed version of the charm, and kind of defeats some of the purpose of charms. Actions are what we have, and we should use and dogfood them. What would be ideal here is for actions to be able to stream output files to clients running actions, but that is explicitly not a target for the current actions rework and we will need to make do for quite some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants