Skip to content

Commit c5fc2e5

Browse files
authored
Merge branch 'main' into aider-tasks-agentapi-support
2 parents 324840a + e34320c commit c5fc2e5

File tree

38 files changed

+2033
-249
lines changed

38 files changed

+2033
-249
lines changed

.github/workflows/ci.yaml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ jobs:
1313
steps:
1414
- name: Check out code
1515
uses: actions/checkout@v5
16+
- name: Detect changed files
17+
uses: dorny/paths-filter@v3
18+
id: filter
19+
with:
20+
list-files: shell
21+
filters: |
22+
shared:
23+
- 'test/**'
24+
- 'package.json'
25+
- 'bun.lock'
26+
- 'bunfig.toml'
27+
- 'tsconfig.json'
28+
- '.github/workflows/ci.yaml'
29+
- 'scripts/ts_test_auto.sh'
30+
- 'scripts/terraform_test_all.sh'
31+
- 'scripts/terraform_validate.sh'
32+
modules:
33+
- 'registry/**/modules/**'
34+
all:
35+
- '**'
1636
- name: Set up Terraform
1737
uses: coder/coder/.github/actions/setup-tf@main
1838
- name: Set up Bun
@@ -27,10 +47,22 @@ jobs:
2747
- name: Install dependencies
2848
run: bun install
2949
- name: Run TypeScript tests
30-
run: bun test
50+
env:
51+
ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_files }}
52+
SHARED_CHANGED: ${{ steps.filter.outputs.shared }}
53+
MODULE_CHANGED_FILES: ${{ steps.filter.outputs.modules_files }}
54+
run: bun tstest
3155
- name: Run Terraform tests
32-
run: ./scripts/terraform_test_all.sh
56+
env:
57+
ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_files }}
58+
SHARED_CHANGED: ${{ steps.filter.outputs.shared }}
59+
MODULE_CHANGED_FILES: ${{ steps.filter.outputs.modules_files }}
60+
run: bun tftest
3361
- name: Run Terraform Validate
62+
env:
63+
ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_files }}
64+
SHARED_CHANGED: ${{ steps.filter.outputs.shared }}
65+
MODULE_CHANGED_FILES: ${{ steps.filter.outputs.modules_files }}
3466
run: bun terraform-validate
3567
validate-style:
3668
name: Check for typos and unformatted code
@@ -50,7 +82,7 @@ jobs:
5082
- name: Validate formatting
5183
run: bun fmt:ci
5284
- name: Check for typos
53-
uses: crate-ci/typos@v1.37.2
85+
uses: crate-ci/typos@v1.38.1
5486
with:
5587
config: .github/typos.toml
5688
validate-readme-files:

.icons/folder.svg

Lines changed: 1 addition & 0 deletions
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"fmt": "bun x prettier --write . && terraform fmt -recursive -diff",
55
"fmt:ci": "bun x prettier --check . && terraform fmt -check -recursive -diff",
66
"terraform-validate": "./scripts/terraform_validate.sh",
7-
"test": "./scripts/terraform_test_all.sh",
7+
"tftest": "./scripts/terraform_test_all.sh",
8+
"tstest": "./scripts/ts_test_auto.sh",
89
"update-version": "./update-version.sh"
910
},
1011
"devDependencies": {
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
display_name: Archive
3+
description: Create automated and user-invocable scripts that archive and extract selected files/directories with optional compression (gzip or zstd).
4+
icon: ../../../../.icons/folder.svg
5+
verified: false
6+
tags: [backup, archive, tar, helper]
7+
---
8+
9+
# Archive
10+
11+
This module installs small, robust scripts in your workspace to create and extract tar archives from a list of files and directories. It supports optional compression (gzip or zstd). The create command prints only the resulting archive path to stdout; operational logs go to stderr. An optional stop hook can also create an archive automatically when the workspace stops, and an optional start hook can wait for an archive on-disk and extract it on start.
12+
13+
```tf
14+
module "archive" {
15+
count = data.coder_workspace.me.start_count
16+
source = "registry.coder.com/coder-labs/archive/coder"
17+
version = "0.0.1"
18+
agent_id = coder_agent.example.id
19+
20+
paths = ["./projects", "./code"]
21+
}
22+
```
23+
24+
## Features
25+
26+
- Installs two commands into the workspace `$PATH`: `coder-archive-create` and `coder-archive-extract`.
27+
- Creates a single `.tar`, `.tar.gz`, or `.tar.zst` containing selected paths (depends on `tar`).
28+
- Optional compression: `gzip`, `zstd` (depends on `gzip` or `zstd`).
29+
- Stores defaults so commands can be run without arguments (supports overriding via CLI flags).
30+
- Logs and status messages go to stderr, the create command prints only the final archive path to stdout.
31+
- Optional:
32+
- `create_on_stop` to create an archive automatically when the workspace stops.
33+
- `extract_on_start` to wait for an archive to appear and extract it on start.
34+
35+
> [!WARNING]
36+
> The `create_on_stop` feature uses the `coder_script` `run_on_stop` which may not work as expected on certain templates without additional provider configuration. The agent may be terminated before the script completes. See [coder/coder#6174](https://github.com/coder/coder/issues/6174) for provider-specific workarounds and [coder/coder#6175](https://github.com/coder/coder/issues/6175) for tracking a fix.
37+
38+
## Usage
39+
40+
Basic example:
41+
42+
```tf
43+
module "archive" {
44+
count = data.coder_workspace.me.start_count
45+
source = "registry.coder.com/coder-labs/archive/coder"
46+
version = "0.0.1"
47+
agent_id = coder_agent.example.id
48+
49+
# Paths to include in the archive (files or directories).
50+
directory = "~"
51+
paths = [
52+
"./projects",
53+
"./code",
54+
]
55+
}
56+
```
57+
58+
Customize compression and output:
59+
60+
```tf
61+
module "archive" {
62+
count = data.coder_workspace.me.start_count
63+
source = "registry.coder.com/coder-labs/archive/coder"
64+
version = "0.0.1"
65+
agent_id = coder_agent.example.id
66+
67+
directory = "/"
68+
paths = ["/etc", "/home"]
69+
compression = "zstd" # "gzip" | "zstd" | "none"
70+
output_dir = "/tmp/backup" # defaults to /tmp
71+
archive_name = "my-backup" # base name (extension is inferred from compression)
72+
}
73+
```
74+
75+
Enable auto-archive on stop:
76+
77+
```tf
78+
module "archive" {
79+
count = data.coder_workspace.me.start_count
80+
source = "registry.coder.com/coder-labs/archive/coder"
81+
version = "0.0.1"
82+
agent_id = coder_agent.example.id
83+
84+
# Creates /tmp/coder-archive.tar.gz of the users home directory (defaults).
85+
create_on_stop = true
86+
}
87+
```
88+
89+
Extract on start:
90+
91+
```tf
92+
module "archive" {
93+
count = data.coder_workspace.me.start_count
94+
source = "registry.coder.com/coder-labs/archive/coder"
95+
version = "0.0.1"
96+
agent_id = coder_agent.example.id
97+
98+
# Where to look for the archive file to extract:
99+
output_dir = "/tmp"
100+
archive_name = "my-archive"
101+
compression = "gzip"
102+
103+
# Waits up to 5 minutes for /tmp/my-archive.tar.gz to be present, note that
104+
# using a long timeout will delay every workspace start by this much until the
105+
# archive is present.
106+
extract_on_start = true
107+
extract_wait_timeout_seconds = 300
108+
}
109+
```
110+
111+
## Command usage
112+
113+
The installer writes the following files:
114+
115+
- `$CODER_SCRIPT_DATA_DIR/archive-lib.sh`
116+
- `$CODER_SCRIPT_BIN_DIR/coder-archive-create`
117+
- `$CODER_SCRIPT_BIN_DIR/coder-archive-extract`
118+
119+
Create usage:
120+
121+
```console
122+
coder-archive-create [OPTIONS] [PATHS...]
123+
-c, --compression <gzip|zstd|none> Compression algorithm (default from module)
124+
-C, --directory <DIRECTORY> Change to directory for archiving (default from module)
125+
-f, --file <ARCHIVE> Output archive file (default from module)
126+
-h, --help Show help
127+
```
128+
129+
Extract usage:
130+
131+
```console
132+
coder-archive-extract [OPTIONS]
133+
-c, --compression <gzip|zstd|none> Compression algorithm (default from module)
134+
-C, --directory <DIRECTORY> Extract into directory (default from module)
135+
-f, --file <ARCHIVE> Archive file to extract (default from module)
136+
-h, --help Show help
137+
```
138+
139+
Examples:
140+
141+
- Use Terraform defaults:
142+
143+
```
144+
coder-archive-create
145+
```
146+
147+
- Override compression and output file at runtime:
148+
149+
```
150+
coder-archive-create --compression zstd --file /tmp/backups/archive.tar.zst
151+
```
152+
153+
- Add extra paths on the fly (in addition to the Terraform defaults):
154+
155+
```
156+
coder-archive-create /etc/hosts
157+
```
158+
159+
- Extract an archive into a directory:
160+
161+
```
162+
coder-archive-extract --file /tmp/backups/archive.tar.gz --directory /tmp/restore
163+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
mock_provider "coder" {}
2+
3+
run "apply_defaults" {
4+
command = apply
5+
6+
variables {
7+
agent_id = "agent-123"
8+
paths = ["~/project", "/etc/hosts"]
9+
}
10+
11+
assert {
12+
condition = output.archive_path == "/tmp/coder-archive.tar.gz"
13+
error_message = "archive_path should be empty when archive_name is not set"
14+
}
15+
}
16+
17+
run "apply_with_name" {
18+
command = apply
19+
20+
variables {
21+
agent_id = "agent-123"
22+
paths = ["/etc/hosts"]
23+
archive_name = "nightly"
24+
output_dir = "/tmp/backups"
25+
compression = "zstd"
26+
create_archive_on_stop = true
27+
}
28+
29+
assert {
30+
condition = output.archive_path == "/tmp/backups/nightly.tar.zst"
31+
error_message = "archive_path should be computed from archive_name + output_dir + extension"
32+
}
33+
}

0 commit comments

Comments
 (0)