Repository navigation
feat(docker): add Docker resources #649
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
Merged
john-royal
merged 28 commits into
alchemy-run:main
from
austinm911:codex/docker-v2-resources
Jun 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c3d9406
feat(docker): add Docker resources
austinm911 7470843
fix(docker): refine inspect API and example secret
austinm911 6b93eb5
Merge remote-tracking branch 'origin/main' into codex/docker-v2-resou…
sam-goodwin 41fce13
fix(docker): align with main after merge
sam-goodwin 60c1eb2
refactor(docker): auto physical names + drop Date.now() from images
sam-goodwin 0e948ae
move helpers to bottom
john-royal 3b2f7bd
refactor
john-royal 4cee735
update aws and cloudflare to use new docker api
john-royal 45b7a4b
replace old docker utils with Docker.materialize
john-royal e10aba6
remove leftover helpers
john-royal a7c3125
progress
john-royal 9ff3c6f
add comments to docker client
john-royal 57fc593
fix any in providers
john-royal ef3b931
allow RemoteImage to re-tag and push; remove remote pull from Image
john-royal 61b2040
write docker build logs as session notes
john-royal 6a8373c
add more tests
john-royal c2fe7fd
more tests
john-royal 3092a58
replace fix (separate pr)
john-royal f34cfae
log when pushing image
john-royal a04dc6e
Merge branch 'main' into codex/docker-v2-resources
john-royal 745bca5
add back inspectContainer
john-royal d9f7000
fix type errors
john-royal 72699e2
simplify image build
john-royal 1d3e2d6
mv helper
john-royal ce18557
relocate helpers
john-royal 29acf6a
fix import
john-royal ba6d340
claude pr feedback fixes
john-royal d67cdfb
Merge branch 'main' into codex/docker-v2-resources
john-royal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| # Docker PostgreSQL Example | ||
|
|
||
| This example provisions PostgreSQL 18 Alpine with Docker resources: | ||
|
|
||
| - `Docker.RemoteImage` pulls `postgres:18-alpine` | ||
| - `Docker.Network` creates an app network | ||
| - `Docker.Volume` creates persistent database storage | ||
| - `Docker.Container` starts PostgreSQL with a redacted password, a network alias, a named volume, and a host port | ||
| - `Docker.Container.inspect` returns the bound host port | ||
|
|
||
| Docker resources use the active Docker CLI context. That can be Docker Desktop, a remote Docker host, an SSH context, or a CI runner daemon. | ||
|
|
||
| These resources are separate from `Cloudflare.Container`. The bridge between Docker and cloud container platforms is an image reference or registry digest, not a swappable container object. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```sh | ||
| bun install | ||
| POSTGRES_PASSWORD=change-me bun run --filter docker-postgres-example deploy | ||
| bun run --filter docker-postgres-example destroy | ||
| ``` | ||
|
|
||
| If `POSTGRES_PASSWORD` is omitted, the example uses a redacted development default. | ||
|
|
||
| The stack publishes PostgreSQL on `localhost:15432`: | ||
|
|
||
| ```sh | ||
| psql postgres://alchemy:change-me@localhost:15432/app | ||
| ``` |
This file contains hidden or 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,67 @@ | ||
| import * as Alchemy from "alchemy"; | ||
| import * as Docker from "alchemy/Docker"; | ||
| import * as Config from "effect/Config"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Redacted from "effect/Redacted"; | ||
|
|
||
| const POSTGRES_PORT = 15432; | ||
| const POSTGRES_CONTAINER = "alchemy-example-postgres"; | ||
| const EMPTY_RUNTIME: Docker.ContainerRuntimeInfo = { ports: {} }; | ||
|
|
||
| export default Alchemy.Stack( | ||
| "DockerPostgresExample", | ||
| { providers: Docker.providers(), state: Alchemy.localState() }, | ||
| Effect.gen(function* () { | ||
| const password = yield* Config.redacted("POSTGRES_PASSWORD").pipe( | ||
| Config.withDefault(Redacted.make("alchemy-postgres")), | ||
| ); | ||
|
|
||
| const image = yield* Docker.RemoteImage("postgres-image", { | ||
| name: "postgres", | ||
| tag: "18-alpine", | ||
| alwaysPull: false, | ||
| }); | ||
| const network = yield* Docker.Network("app-network"); | ||
| const data = yield* Docker.Volume("postgres-data"); | ||
|
|
||
| const postgres = yield* Docker.Container("postgres", { | ||
| name: POSTGRES_CONTAINER, | ||
| image, | ||
| environment: { | ||
| POSTGRES_DB: "app", | ||
| POSTGRES_USER: "alchemy", | ||
| POSTGRES_PASSWORD: password, | ||
| }, | ||
| ports: [{ external: POSTGRES_PORT, internal: 5432 }], | ||
| volumes: [ | ||
| { | ||
| hostPath: data.name, | ||
| containerPath: "/var/lib/postgresql/data", | ||
| }, | ||
| ], | ||
| networks: [{ name: network.name, aliases: ["postgres"] }], | ||
| healthcheck: { | ||
| cmd: ["CMD-SHELL", "pg_isready -U alchemy -d app"], | ||
| interval: "5s", | ||
| timeout: "5s", | ||
| retries: 10, | ||
| }, | ||
| start: true, | ||
| }); | ||
|
|
||
| const runtime = yield* Docker.Container.inspect(POSTGRES_CONTAINER).pipe( | ||
| Effect.catchTag("DockerCommandError", () => | ||
| Effect.succeed(EMPTY_RUNTIME), | ||
| ), | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is Docker.Container.inspect? Should this be Docker.inspectContainer?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| return { | ||
| container: postgres.name, | ||
| image: image.imageRef, | ||
| network: network.name, | ||
| volume: data.name, | ||
| hostPort: runtime.ports["5432/tcp"] ?? POSTGRES_PORT, | ||
| connectionString: `postgres://alchemy:***@localhost:${POSTGRES_PORT}/app`, | ||
| }; | ||
| }), | ||
| ); | ||
This file contains hidden or 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,21 @@ | ||
| { | ||
| "name": "docker-postgres-example", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "license": "Apache-2.0", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/alchemy-run/alchemy-effect.git", | ||
| "directory": "examples/docker-postgres" | ||
| }, | ||
| "type": "module", | ||
| "scripts": { | ||
| "deploy": "alchemy deploy", | ||
| "destroy": "alchemy destroy", | ||
| "build": "tsgo --noEmit -p tsconfig.json" | ||
| }, | ||
| "dependencies": { | ||
| "alchemy": "workspace:*", | ||
| "effect": "catalog:" | ||
| } | ||
| } |
This file contains hidden or 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,16 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "include": ["alchemy.run.ts"], | ||
| "compilerOptions": { | ||
| "noEmit": true, | ||
| "rootDir": ".", | ||
| "module": "Preserve", | ||
| "moduleResolution": "Bundler", | ||
| "target": "ESNext" | ||
| }, | ||
| "references": [ | ||
| { | ||
| "path": "../../packages/alchemy/tsconfig.json" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the
Randomresource to generate itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done