Skip to content
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

Add dev container #183

Merged
merged 3 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
ARG VARIANT=3.1-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}

# Install Rails
# RUN gem install rails webdrivers

# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
# The value is a comma-separated list of allowed domains
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"

# [Choice] Node.js version: lts/*, 16, 14, 12, 10
ARG NODE_VERSION="lts/*"
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends imagemagick ffmpeg

# [Optional] Uncomment this line to install additional gems.
RUN gem install foreman

# [Optional] Uncomment this line to install global node packages.
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g yarn" 2>&1
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/ruby-rails-postgres
// Update the VARIANT arg in docker-compose.yml to pick a Ruby version
{
"name": "Black Candy",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": []
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
"forwardPorts": [
3000
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bundle install && yarn install && rake db:prepare",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
67 changes: 67 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
args:
# Update 'VARIANT' to pick a version of Ruby: 3, 3.1, 3.0, 2, 2.7, 2.6
# Append -bullseye or -buster to pin to an OS version.
# Use -bullseye variants on local arm64/Apple Silicon.
VARIANT: "3.1-bullseye"
# Optional Node.js version to install
NODE_VERSION: "12"

volumes:
- ..:/workspace:cached
- ~/media_data:/media_data
- bundler-data:/usr/local/bundle

environment:
DB_HOST: postgres
DB_USER: postgres
REDIS_DATA_URL: redis://redis:6379/0
REDIS_SIDEKIQ_URL: redis://redis:6379/1
REDIS_CABLE_URL: redis://redis:6379/2
MEDIA_PATH: /media_data

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
networks:
- external_network
- internal_network
# Uncomment the next line to use a non-root user for all processes.
user: vscode

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

postgres:
image: postgres:11.1-alpine
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- internal_network
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

redis:
image: redis:6.0-alpine
volumes:
- redis-data:/data
networks:
- internal_network

volumes:
postgres-data:
redis-data:
bundler-data:

networks:
external_network:
internal_network:
internal: true
2 changes: 0 additions & 2 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
postgres: postgres
redis: redis-server --dir .redis_data
web: rails s -p 3000
sidekiq: sidekiq
css: rails dartsass:watch
Expand Down
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,15 @@ $ docker-compose restart
- Postgres 11
- Redis 6.0
- Nodejs 12
- Yarn 1.22
- Imagemagick 7
- ffmpeg 4.3
- Yarn
- Imagemagick
- ffmpeg

You can use [nix](https://nixos.org) to setup dev environment easily.
You can use VS Code Remote Containers or GitHub Codespaces to setup dev environment easily.
For more infomations about dev container, please visit this link <https://code.visualstudio.com/docs/remote/create-dev-container>.

```shell
# First, install nix. You can check out the nix doc for more details.
$ curl -L https://nixos.org/nix/install | sh

# Then clone the repo.
$ git clone https://github.com/aidewoode/black_candy.git

# Change to the directory.
$ cd black_candy

# Go into nix shell, the nix shell will auto setup all dev requirements you need.
$ nix-shell

# Install requirement gems.
$ bundle

# Install npm packages.
$ yarn

# Setup database.
$ rails db:setup

# Finally, start all services.
$ ./bin/dev
```
After the dev container has been built. You can run `./bin/dev` in terminal to start all services.
Then visit <http://localhost:3000> use initial admin user to login (email: admin@admin.com, password: foobar).

## Test

Expand Down
38 changes: 0 additions & 38 deletions shell.nix

This file was deleted.