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

feat: Docker development environment #1337

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Want to contribute? Great. Please review the following guidelines carefully and
6. [Updating existing documentations](#updating-existing-documentations)
7. [Other contributions](#other-contributions)
8. [Coding conventions](#coding-conventions)
9. [Questions?](#questions)
9. [Developing in Docker](#developing-in-docker)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section is missing in the file (has not been committed)?

10. [Questions?](#questions)

## Reporting bugs

Expand Down Expand Up @@ -79,6 +80,23 @@ Follow the following steps to update documentations to their latest version:
* no trailing whitespace; blank lines should have no spaces; new line at end-of-file
* use the same coding style as the rest of the codebase

## Developing in Docker

To set up a Docker development enviroment:

1. Install [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/).
2. Navigate to the root of this repository.
3. `cp sample.env .env`
4. `docker-compose up -d`
5. `docker-compose run --rm --service-ports devdocs`

You should now be in a bash shell inside the Docker container. The repo is mounted at `/home/devuser`, so any changes you make there will be reflected on the host (your machine) and vice versa. Commands can all be run inside the container:

1. `thor docs:download --default` to get the default docs.
2. `rackup -o 0.0.0.0` to start the server

Navigate to `http://localhost:9292` to see the running site.

## Questions?

If you have any questions, please feel free to ask them on the contributor chat room on [Gitter](https://gitter.im/FreeCodeCamp/DevDocs).
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
.bundle
.bash_history
.env
log
tmp
public/assets
Expand Down
44 changes: 44 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM ruby:2.6.5

ENV LANG=C.UTF-8
ENV ENABLE_SERVICE_WORKER=true

ARG USER_ID
ARG GROUP_ID

RUN apt-get update && \
apt-get -y install git nodejs libcurl4 sudo && \
gem install bundler

# Create the dev user, add them to sudoers and set up a home dir
# Adapted slightly from this excellent blog post:
# https://jtreminio.com/blog/running-docker-containers-as-current-host-user
RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \
groupadd -g ${GROUP_ID} devuser &&\
useradd -l -u ${USER_ID} -g devuser devuser &&\
usermod -aG sudo devuser &&\
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers &&\
install -d -m 0755 -o devuser -g devuser /home/devuser &&\
chown --changes --silent --no-dereference --recursive \
--from=33:33 ${USER_ID}:${GROUP_ID} \
/home/devuser \
;fi

# Host directories cannot be mounted by Dockerfiles so we have to use
# a temporary directory to hold the lock files while the gems are installed.
WORKDIR /devdocs/

COPY Gemfile Gemfile.lock Rakefile /devdocs/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running docker build - < Dockerfile-dev failed:

Step 9/14 : COPY Gemfile Gemfile.lock Rakefile /devdocs/
COPY failed: stat /var/lib/docker/tmp/docker-builder202400793/Gemfile: no such file or directory

(Not exactly sure how it is meant to be used, though…)


RUN bundle install && rm -rf /devdocs/

WORKDIR /home/devuser/

EXPOSE 9292

# This entrypoint lets you
# docker-compose run --rm --service-ports devdocs
# straight into a bash shell
ENTRYPOINT [ "/bin/bash" ]

USER devuser
13 changes: 13 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.7'
services:
devdocs:
build:
context: .
dockerfile: Dockerfile-dev
args:
USER_ID: ${USER_ID:-0}
GROUP_ID: ${GROUP_ID:-0}
volumes:
- ${PWD}:/home/devuser
ports:
- "9292:9292"
4 changes: 4 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Docker development config
USER_ID=1000
GROUP_ID=1000
COMPOSE_FILE=docker-compose.dev.yml