Skip to content

Commit 37126eb

Browse files
authored
Merge pull request #6 from datarockets/a-few-moments-later
Major migrate to devcontainer spec plush refreshing the approach
2 parents f2c6371 + bd70af9 commit 37126eb

28 files changed

Lines changed: 406 additions & 263 deletions

.github/dependabot.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: release-features
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- features/**
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
packages: write
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Publish features
23+
uses: devcontainers/action@v1
24+
with:
25+
publish-features: "true"
26+
base-path-to-features: "./features"
27+
generate-docs: "true"
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: release-image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- image/**
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Log in to GitHub Container Registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and push
29+
uses: docker/build-push-action@v6
30+
with:
31+
context: ./image
32+
push: true
33+
tags: ghcr.io/${{ github.repository_owner }}/devcontainer:latest
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: release-template
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- template/**
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
packages: write
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Check version consistency
23+
run: |
24+
TEMPLATE_VERSION=$(jq -r '.version' template/devcontainer-template.json)
25+
DEVCONTAINER_VERSION=$(cat template/.devcontainer/VERSION | tr -d '[:space:]')
26+
if [ "$TEMPLATE_VERSION" != "$DEVCONTAINER_VERSION" ]; then
27+
echo "Version mismatch: devcontainer-template.json has '$TEMPLATE_VERSION' but .devcontainer/VERSION has '$DEVCONTAINER_VERSION'"
28+
exit 1
29+
fi
30+
echo "Versions match: $TEMPLATE_VERSION"
31+
32+
- name: Publish template
33+
uses: devcontainers/action@v1
34+
with:
35+
publish-templates: "true"
36+
base-path-to-templates: "./template"
37+
generate-docs: "true"
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# To avoid duplicates with template's content
2+
/.claude
3+
/.opencode
4+
/.devcontainer
5+
/bin
6+
7+
/tmp

Dockerfile

Lines changed: 0 additions & 71 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,42 @@
22

33
We use devcontainer to develop our fully dockerized projects.
44

5-
It allows us to use Visual Studio Code's developing inside a container feature for project with multiple services.
5+
## Prerequisites
66

7-
## Fully dockerized projects
7+
1. Have [datarockets/dotfiles](https://github.com/datarockets/dotfiles) installed
8+
2. Have [datarockets/dotai](https://github.com/datarockets/dotai) installed
89

9-
We use docker-compose for setting up dockerized projects. Every service of the dockerized project exists in its own container with all the dependencies (npm packages, ruby gems). If we avoid duplicating dependencies on developer's local machine it means we loose and ability to do many of the things in our IDE, like debugging or linting or formatting.
10+
> [!NOTE]
11+
> Both can be skipped, but will require to tweak your `devcontainer.json`.
1012
11-
Visual Studio Code supports ["developing inside a container"](https://code.visualstudio.com/docs/remote/containers). It allows us to attach to a container and run, in example, linter right inside the container. This is one of the ways to go: you start your services with docker-compose, attach to a running container and perform debugging there, here is a [proof of concept](https://github.com/datarockets/vscode-docker-compose-poc).
13+
## Usage example
1214

13-
This approach with attaching to different containers has a number of limitation: 1) if you have multiple services you need to open a multiple vscode windows attached to different containers to work on different services simultaneously; 2) you still will miss some of the IDE features, like git integration (we don't have git installed in service container and mounting .git folder wont work since we don't mount all the service folder in one particular service container), and embedded terminal.
15+
Setup devcontainer in your project from the template:
1416

15-
Instead of attaching to service containers serparately, we add one more service "devcontainer" to the docker-compose.yml and attach to it with vscode. We mount the whole project folder with all the services to "devcontainer" as well, we also mount dependencies folders for every service so they become available and runnable in the devcontainer. It allows us to run linters and tests the same way we would do if we have all the dependencies installed on developer's machine.
16-
17-
See an [example](examples/ruby-api-with-spa-frontend) for a project that uses Ruby for API and [dreact](https://github.com/datarockets/dreact) for frontend.
18-
19-
We use official images (e.g. [node](https://hub.docker.com/_/node)) for service containers but we install compilers and interpreters using [asdf](https://asdf-vm.com/) in the devcontainer. We have to be conscious about installing the same version of compiler or interpreter in the devcontainer in order to avoid possible problems.
20-
21-
22-
## Limitations
23-
24-
We have to use the same OS for service containers and for devcontainer, e.g. Debian Bullseye. This is because different OS may use different system dependencies which highly influence how we build native parts of our dependencies for different services. E.g. Alpine linux uses musl when Debian uses glibc and gem's native extensions compiled in Alpine-based container aren't runnable in Debian container.
25-
26-
27-
## Tags
28-
29-
We have [base container](#base-container-with-dev-tools-buster) with some tools installed. You can inherit from it and install any needed compilers and interpreters additionally, using asdf.
30-
31-
Compiling interpreters and compilers takes some CPU time so we also have a number of pre-built containers for our stacks: [Rails API with SPA frontend](#rails-api-with-spa-frontend-node-node_version-ruby-ruby_version-buster).
32-
33-
### Base container with dev tools: `bullseye`
34-
35-
[ghcr.io/datarockets/devcontainer:bullseye](https://ghcr.io/datarockets/devcontainer:bullseye).
36-
37-
It has a number of tools for development installed: doas, git, vim, tmux, ping. See [`Dockerfile`](Dockerfile) for more information.
38-
39-
You can inherit your own devcontainer from it and install any wanted dependencies you need:
40-
41-
```Dockerfile
42-
ARG DOTFILES_REPO="https://github.com/datarockets/dotfiles.git"
43-
ARG DOTFILES_INSTALL_COMMAND="RCRC=$HOME/.dotfiles/rcrc rcup"
44-
FROM ghcr.io/datarockets/devcontainer:bullseye
45-
46-
RUN apt-get install postgresql postgresql-contrib
47-
48-
USER dev
49-
SHELL ["/bin/zsh", "-ic"]
50-
51-
RUN asdf asdf plugin-add ruby; \
52-
asdf install ruby 3.0.1; \
53-
asdf global ruby 3.0.1
17+
```bash
18+
devcontainer templates apply -t ghcr.io/datarockets/devcontainer/template:latest
5419
```
5520

56-
Having postgresql installed in the devcontainer will allow you to use `psql`.
21+
Use directly in your `devcontainer.json`:
5722

58-
### Rails API with SPA frontend: `node-NODE_VERSION-ruby-RUBY_VERSION-bullseye`
23+
```json
24+
{
25+
"image": "ghcr.io/datarockets/devcontainer:latest",
26+
"features": {
27+
// Makes your host docker socket available in the container
28+
"ghcr.io/datarockets/devcontainer/feature-with-docker": {},
5929

60-
[ghcr.io/datarockets/devcontainer:node-18.9.0-ruby-3.1.2-bullseye](https://ghcr.io/datarockets/devcontainer:node-18.9.0-ruby-3.1.2-bullseye)
30+
// Keeps .local directory in container persistent as a volume (project level)
31+
"ghcr.io/datarockets/devcontainer/feature-mount-perproject-dotlocal": {},
6132

62-
See the [buld.yml](.github/workflows/build.yml#L36-L37) for Ruby and Node versions available.
33+
// Keeps some cache files in container persistent as a volume (host level)
34+
"ghcr.io/datarockets/devcontainer/feature-mount-permachine-caches": {},
6335

36+
// Binds your overrides of dotfiles to container (dotfiles themselves are already in container)
37+
"ghcr.io/datarockets/devcontainer/feature-mount-dotfiles-local": {},
6438

65-
## Contribution
66-
67-
Feel free to create issues and propose pull requests.
39+
// Binds your dotai files
40+
"ghcr.io/datarockets/devcontainer/feature-mount-dotai": {},
41+
},
42+
}
43+
```

examples/ruby-api-with-spa-frontend/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)