Skip to content

Add Docker deployment #175

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
merged 2 commits into from
Mar 14, 2023
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.git/
/_site/
/_posts/
/assets/
/_docs/
/_includes/
/.idea/
/.run/
/*.iml
/README.md
49 changes: 49 additions & 0 deletions .run/intellij-rust.github.io.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="intellij-rust.github.io" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="intellij-rust.github.io" />
<option name="containerName" value="intellij-rust.github.io" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="8080" />
<option name="hostIp" value="0.0.0.0" />
<option name="hostPort" value="8080" />
</DockerPortBindingImpl>
</list>
</option>
<option name="sourceFilePath" value="Dockerfile" />
<option name="volumeBindings">
Copy link
Member

@Undin Undin Feb 13, 2023

Choose a reason for hiding this comment

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

As I understand, volumes here are needed to be able to apply changes made locally without rerunning configuration. But why only _posts and assets/posts/ directories? What if I want to change some other places? Maybe it's better to add volume for the whole project directory instead of copying its files during docker image building?

Copy link
Member Author

Choose a reason for hiding this comment

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

The trick here is to preserve Gemfile and Gemfile.lock that were patched during the image build. I couldn't find a better way to do that, but if you know one – please share it.

As we can see at https://pages.github.com/versions, GitHub uses Ruby 2.7.4. But I cannot deploy the website locally using this Ruby version on my ARM-based machine because of some dependencies incompatibilities. That's why my Dockerfile uses a newer Ruby version and thus has to patch the gem dependencies to make it work.

I've extended the list of directories: _posts/, assets/, _docs/, _includes/. They seem to be the most important directories for changes to be auto-applied.

And by @vlad20012 advice, I've added all of them to .dockerignore not to do the useless job, and I've also fixed the Ruby version to avoid incompatibilities in the future.

<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/intellij-rust.github.io/_posts/" />
<option name="hostPath" value="$PROJECT_DIR$/_posts/" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/intellij-rust.github.io/assets/" />
<option name="hostPath" value="$PROJECT_DIR$/assets/" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/intellij-rust.github.io/_docs" />
<option name="hostPath" value="$PROJECT_DIR$/_docs/" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/intellij-rust.github.io/_includes" />
<option name="hostPath" value="$PROJECT_DIR$/_includes/" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/intellij-rust.github.io/_site" />
<option name="hostPath" value="$PROJECT_DIR$/_site/" />
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ruby:3.2

RUN apt-get update && apt-get install -y build-essential

COPY . /intellij-rust.github.io
WORKDIR /intellij-rust.github.io

RUN gem install github-pages jekyll jekyll-feed && bundle add webrick && bundle update && bundle install

EXPOSE 8080

WORKDIR /intellij-rust.github.io
CMD ["bundle", "exec", "jekyll", "serve", "--host", "0.0.0.0", "--port", "8080", "--future"]
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Install [Ruby](https://www.ruby-lang.org) and [Bundler](http://bundler.io/).
There is `.ruby-version` file for [rbenv](https://github.com/rbenv/rbenv) if you like.
You will probably need GCC, Make, AutoConf and NodeJS installed.
You will probably need GCC, Make, AutoConf and NodeJS installed.

```bash
$ bundle install
Expand All @@ -15,7 +15,7 @@ $ bundle exec jekyll serve --future

If you are using Windows, it's better not to fight with Ruby Installer. I use WSL and works
pretty flawlessly, except file change watching (see
[tracking issue](https://github.com/Microsoft/BashOnWindows/issues/216)). So you'll have to run
[tracking issue](https://github.com/Microsoft/BashOnWindows/issues/216)). So you'll have to run
this instead:

```bash
Expand All @@ -28,3 +28,20 @@ To workaround lack of watching, you can do:
$ bundle exec jekyll serve --detach
$ while (bundle exec jekyll build --incremental); do sleep 5; done
```

## Docker

Run `intellij-rust.github.io` configuration directly from IntelliJ IDEA. The website will be accessible at `http://localhost:8080/`.
Any changes made in `_posts`, `assets`, `_docs`, and `_includes` directories will be reflected immediately.

Alternatively, you can use the following commands from the terminal:
```bash
$ docker build -t intellij-rust.github.io .
$ docker run \
-v $PWD/_posts:/intellij-rust.github.io/_posts \
-v $PWD/assets:/intellij-rust.github.io/assets \
-v $PWD/_docs:/intellij-rust.github.io/_docs \
-v $PWD/_includes:/intellij-rust.github.io/_includes \
-v $PWD/_site:/intellij-rust.github.io/_site \
-p 8080:8080 -it intellij-rust.github.io
```
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
title: IntelliJ Rust
email: ""
description: Open-source Rust plugin for IntelliJ-based IDEs
repository: intellij-rust/intellij-rust.github.io

collections:
docs:
Expand Down