Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(registry/coder/modules): add archive module#422

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mafredri wants to merge6 commits intomain
base:main
Choose a base branch
Loading
frommafredri/module-archive

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedSep 16, 2025
edited
Loading

This change adds a newarchive module to the Coder registry. It can be used to archive user-data from pre-defined locations and restore it as well.

Here we also explore:

  • A new method of passing arrays from Terraform to Bash
  • A new method of writing Bash scripts that minimizes the interaction with terraform interpolation
  • Extensive test-suite that not only tests that Terraform options can be selected, but also the resulting script behaviors

@mafredrimafredriforce-pushed themafredri/module-archive branch 14 times, most recently fromc9efaa3 to90f7dbdCompareSeptember 18, 2025 13:15
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've been testing this out locally.
Nice work! Left some comments down below (none blocking).
LMK when this is ready for a more in-depth review.

Comment on lines 13 to 31
- Depends on: `tar` (and `gzip` or `zstd` if you select those compression modes)
- Installed scripts:
- `$CODER_SCRIPT_BIN_DIR/coder-archive-create`
- `$CODER_SCRIPT_BIN_DIR/coder-archive-extract`
- Library installed to:
- `$CODER_SCRIPT_DATA_DIR/archive-lib.sh`
- On start (always): installer decodes and writes the library, then generates the wrappers in `$CODER_SCRIPT_BIN_DIR` with Terraform-provided defaults embedded.
- Optional on stop: when enabled, a separate `run_on_stop` script invokes the create command.

## Features

- Create a single `.tar`, `.tar.gz`, or `.tar.zst` containing selected paths.
- Compression algorithms: `gzip`, `zstd`, `none`.
- Defaults for directory, archive path, compression, include/exclude lists come from Terraform and can be overridden at runtime with CLI flags.
- Logs and status messages go to stderr; the create command prints only the final archive path to stdout.
- Strict bash mode and safe invocation of `tar`.
- Optional:
- `run_on_stop` to create an archive automatically when the workspace stops.
- `extract_on_start` to wait for an archive to appear and extract it on start (with timeout).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggestion: you can probably combine these two

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Combine which two? I'm worried about the user experience if we assume that extract on start means you also want to run on stop (if that's what you meant).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry -- I meant simply to combine both sets of bullet points, as there seems to be some slight duplication between them.

mafredri reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I did a major cleanup of the README in822cf15.

Comment on lines 81 to 84
paths = [for v in var.paths : replace(v, "/^~/", "$$HOME")]
exclude_patterns = [for v in var.exclude_patterns : replace(v, "/^~/", "$$HOME")]
directory = replace(var.directory, "/^~/", "$$HOME")
output_dir = replace(var.output_dir, "/^~/", "$$HOME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If I'm reading this correctly, it only handles the~ at the start of the string? I can't see a reason to have it anywhere else tbh.

Should we also match a path separator to avoid expanding e.g.~username into/home/usernameusername?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could, but I'll need to look into if tf replace regex handles replacement like"/^~(\/?)/", "$1". Or we can move this into bash to avoid the repetition. Because we'll need to handle both"~", and"~/..."`.

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed inb48daf9

@mafredrimafredri marked this pull request as ready for reviewSeptember 19, 2025 14:31
@mafredrimafredri changed the title[WIP] feat(registry/coder/modules): add archive modulefeat(registry/coder/modules): add archive moduleSep 19, 2025
mafredriand others added4 commitsSeptember 19, 2025 18:57
Co-authored-by: Cian Johnston <cian@coder.com>
Co-authored-by: Cian Johnston <cian@coder.com>
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice work! Just a couple of nits below.

};

const fileExists = async (id: string, path: string) => {
const res = await sh(id, `test -f ${path} && echo yes || echo no`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: could this just be simplified to

await sh(id, `test -f ${path}; echo $?`);return res.stdout.trim() === "1";

mafredri reacted with thumbs up emoji
const extractDir = "/tmp/extract";
const extract = await bashRun(
id,
`${BIN_DIR}/coder-archive-extract -f ${out} -C ${extractDir}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should we also be validating that these end up in$PATH?

e.g. without${BIN_DIR}

awit bashRun(id, `coder-archive-extract ...`)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can put it in path manually, e.g. setCODER_SCRIPT_BIN_DIR=/usr/local/bin or something. But to make it a truly real test-case, we'd have to be running our commands inside acoder agent spawned environment.

Copy link
Member

@matifalimatifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This change adds a new archive module to the Coder registry. It can be used to archive user-data from pre-defined locations and restore it as well.

Where do these locations live? I see in examples that they are archived in /tmp which is not persistent in our example templates. Should we add examples on how we can archive and upload to an external storage like a s2 bucket and then restore from that?

The 2nd suggestion is to move this tocoder-labs namespace.

@mafredri
Copy link
MemberAuthor

Where do these locations live? I see in examples that they are archived in /tmp which is not persistent in our example templates. Should we add examples on how we can archive and upload to an external storage like a s2 bucket and then restore from that?

That's up to the author currently. They can store the archive in a place that's persisted or upload it. Ideally this module can be kept focused on archiving, and uploading/downloading could be handled by another module or scripted by template author.

I can add an example how upload/download could be implemented.

The 2nd suggestion is to move this tocoder-labs namespace.

Didn't realize we have this, that works 👍🏻

matifali reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@matifalimatifalimatifali left review comments

@johnstcnjohnstcnjohnstcn approved these changes

At least 1 approving review is required to merge this pull request.

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mafredri@johnstcn@matifali

[8]ページ先頭

©2009-2025 Movatter.jp