Skip to content

Commit a17d690

Browse files
authored
Merge pull request #3770 from AlchemyCMS/feature/devcontainer
Add devcontainer and Docker Compose for local development
2 parents 84db3cf + ee6c5d6 commit a17d690

5 files changed

Lines changed: 117 additions & 5 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM ruby:4.0
2+
3+
RUN apt-get update && apt-get install -y \
4+
libsqlite3-dev \
5+
libjemalloc2 \
6+
libvips \
7+
imagemagick \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
ENV LD_PRELOAD=libjemalloc.so.2
11+
ENV RUBY_YJIT_ENABLE=1
12+
13+
RUN curl -fsSL https://bun.sh/install | bash
14+
ENV PATH="/root/.bun/bin:${PATH}"
15+
16+
WORKDIR /workspace
17+
18+
COPY Gemfile Gemfile.lock* alchemy_cms.gemspec ./
19+
COPY lib/alchemy/version.rb lib/alchemy/version.rb
20+
RUN bundle install
21+
22+
COPY package.json bun.lock* ./
23+
RUN bun install

.devcontainer/devcontainer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "Alchemy CMS Development",
3+
"dockerComposeFile": "../docker-compose.yml",
4+
"service": "web",
5+
"workspaceFolder": "/workspace",
6+
"postCreateCommand": "bundle install && bun install && cd spec/dummy && bin/rails db:prepare",
7+
"forwardPorts": [3000],
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"Shopify.ruby-lsp",
12+
"esbenp.prettier-vscode",
13+
"vitest.explorer"
14+
]
15+
}
16+
}
17+
}

CONTRIBUTING.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,35 @@ Here's a quick guide:
2929

3030
1. Fork the repo.
3131

32-
2. Run the tests. We only take pull requests with passing tests, and it's great
32+
2. Set up your development environment. You can either use Docker or install
33+
dependencies locally:
34+
35+
**Using Docker (recommended):**
36+
37+
$ docker compose build
38+
$ docker compose up
39+
40+
This starts the Rails dev server, Sass watcher, and JS bundle watcher.
41+
42+
**Local setup:**
43+
44+
$ bin/setup
45+
$ bin/start
46+
47+
3. Run the tests. We only take pull requests with passing tests, and it's great
3348
to know that you have a clean slate:
3449

3550
$ bundle exec rake
3651

37-
3. Create new branch then make changes and add tests for your changes. Only
52+
4. Create new branch then make changes and add tests for your changes. Only
3853
refactoring and documentation changes require no new tests. If you are adding
3954
functionality or fixing a bug, we need tests!
4055

41-
4. Push to your fork and submit a pull request. If the changes will apply cleanly
56+
5. Push to your fork and submit a pull request. If the changes will apply cleanly
4257
to the latest stable branches and main branch, you will only need to submit one
4358
pull request.
4459

45-
5. If a PR does not apply cleanly to one of its targeted branches, then a separate
60+
6. If a PR does not apply cleanly to one of its targeted branches, then a separate
4661
PR should be created that does. For instance, if a PR applied to main & 2.7-stable but not 2.8-stable, then there should be one PR for main & 2.7-stable and another, separate PR for 2.8-stable.
4762

4863
At this point you're waiting on us. We like to at least comment on, if not

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,18 @@ If you want to contribute to Alchemy ([and we encourage you to do so](CONTRIBUTI
310310

311311
### Preparation
312312

313-
First of all you need to clone your fork to your local development machine. Then you need to install the dependencies with bundler.
313+
First of all you need to clone your fork to your local development machine.
314+
315+
**Using Docker (recommended):**
316+
317+
```bash
318+
$ docker compose build
319+
$ docker compose up
320+
```
321+
322+
This starts the Rails dev server, Sass watcher, and JS bundle watcher. The dev server is available at http://localhost:3000.
323+
324+
**Local setup:**
314325

315326
```bash
316327
$ bin/setup

docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: alchemy_cms
2+
3+
services:
4+
web:
5+
build:
6+
context: .
7+
dockerfile: .devcontainer/Dockerfile
8+
command: bash -c "cd spec/dummy && bin/rails db:prepare && bin/rails server -b 0.0.0.0"
9+
ports:
10+
- "3000:3000"
11+
volumes:
12+
- .:/workspace
13+
- node_modules:/workspace/node_modules
14+
depends_on:
15+
- css
16+
- js
17+
18+
sass:
19+
build:
20+
context: .
21+
dockerfile: .devcontainer/Dockerfile
22+
command: bun run --bun build:css --watch
23+
volumes:
24+
- .:/workspace
25+
- node_modules:/workspace/node_modules
26+
27+
css:
28+
build:
29+
context: .
30+
dockerfile: .devcontainer/Dockerfile
31+
command: bash -c "cd spec/dummy && bin/rails dartsass:watch"
32+
volumes:
33+
- .:/workspace
34+
- node_modules:/workspace/node_modules
35+
36+
js:
37+
build:
38+
context: .
39+
dockerfile: .devcontainer/Dockerfile
40+
command: bun run --bun build:admin:dev
41+
volumes:
42+
- .:/workspace
43+
- node_modules:/workspace/node_modules
44+
45+
volumes:
46+
node_modules:

0 commit comments

Comments
 (0)