Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
feat: First version
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota committed Apr 22, 2020
1 parent 204706f commit beedef9
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 33 deletions.
20 changes: 20 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
update_configs:
- package_manager: "docker"
directory: "/"
update_schedule: "daily"
commit_message:
prefix: "fix"
include_scope: true
- package_manager: "github_actions"
directory: "/"
update_schedule: "daily"
commit_message:
prefix: "ci"
include_scope: true
- package_manager: "java:gradle"
directory: "/tests"
update_schedule: "daily"
commit_message:
prefix: "chore"
include_scope: true
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://developer.github.com/v3/repos/#edit
repository:
name: docker-$$IMAGE_NAME$$
name: docker-mkdocs
description: ""
homepage: https://homecentr.github.io/
private: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/mkdocs"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/mkdocs"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regular_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- cron: '0 6 * * *'

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/mkdocs"

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
build
.gradletasknamecache

**/drawio-exporter

**/.idea/workspace.xml
**/.idea/tasks.xml

Expand Down
52 changes: 51 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
FROM alpine
FROM squidfunk/mkdocs-material:5.1.1 as material

FROM ubuntu:bionic

LABEL maintainer="Lukas Holota <[email protected]>"
LABEL io.homecentr.dependency-version=5.1.1

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

ADD https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/requirements.txt /tmp/requirements.txt
ADD https://github.com/jgraph/drawio-desktop/releases/download/v12.9.13/draw.io-amd64-12.9.13.deb /tmp/drawio.deb

COPY --from=material /usr/local/bin/mkdocs /usr/local/bin/mkdocs

# Install the downloaded package and dependencies required for headless execution
# hadolint ignore=DL3015,DL3008
RUN apt-get update && \
apt-get install --no-install-recommends /tmp/drawio.deb -y && \
apt-get install -y \
libasound2 \
xvfb \
python3-pip \
git && \
# Clean up apt cache
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /tmp

RUN git clone https://github.com/squidfunk/mkdocs-material

WORKDIR /tmp/mkdocs-material

RUN pip3 install --no-cache-dir . && \
pip3 install --no-cache-dir \
mkdocs-drawio-exporter==0.6.1 \
mkdocs-minify-plugin==0.3.0 \
mkdocs-git-revision-date-localized-plugin==0.5.0 \
mkdocs-awesome-pages-plugin==2.2.1

COPY ./entrypoint.sh /entrypoint.sh

RUN rm -rf /tmp/** && chmod a+x /entrypoint.sh


WORKDIR /docs

EXPOSE 8000

ENTRYPOINT [ "/entrypoint.sh" ]
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# HomeCentr - $$IMAGE_NAME$$
Template repository for Docker container repositories
# HomeCentr - mkdocs
Used to generate the documentation site for Homecentr. The image contains [drawio-exporter](https://github.com/LukeCarrier/mkdocs-drawio-exporter) and all dependencies required for running from command line (i.e. in non-interactive environment). Since the set up is not completely straightforward, I thought it could be also useful to others :)

## Project status
## Usage

## Usage (Docker compose)
### Powershell

### Env. variables
### Exposed ports
```Powershell
docker run --rm -it -p 8000:8000 -v ${$PWD}:/docs homecentr/mkdocs
```

### Bash

## Security
```Bash
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs homecentr/mkdocs
```

### Exposed ports

### Vulnerabilities
| Port | Description |
|------|-------------|
| 8000 | Development server |
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
version: "3.7"
services:
$$IMAGE_NAME$$:
mkdocs:
build: .
image: homecentr/$$IMAGE_NAME$$
image: homecentr/mkdocs:local
volumes:
- ./example:/docs
ports:
- 8000:8000
restart: unless-stopped
6 changes: 6 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
CMD=${@:-serve --dev-addr=0.0.0.0:8000}

echo "Running command: xvfb-run -a mkdocs $CMD"

xvfb-run -a mkdocs $CMD
1 change: 1 addition & 0 deletions example/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![My alt text](my-diagram.drawio)
1 change: 1 addition & 0 deletions example/docs/my-diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Chrome" modified="2020-04-22T11:30:30.410Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36" version="13.0.0" etag="uNaqe1rSSnxSgmKARsH0" type="device"><diagram id="V4NEiOsR98XDe-gOuTpI" name="Page-1">3VZNj5swEP01HFsBbhL22GTTbaVWqpT0Y49ePIBbwyBjAvTX1wSD8bKbdtuVKvUSMc8zw8x74yEe2eXtjaRl9gEZCC/0WeuRay8MV0Gof3ugM8DmagBSydkABRY48B9gQN+gNWdQOY4KUSheumCMRQGxcjAqJTauW4LCfWtJU1gAh5iKJfqFM5UNaLTyLf4WeJqNbw58c5LT0dkAVUYZNjOI7D2yk4hqeMrbHYieu5GXIe7NI6dTYRIK9TsBxyMCu43Lxv+0vTm++6ybDF8QU5vqxoaB6f6NiVJlmGJBxd6iW4l1waDP6mvL+rxHLDUYaPAbKNUZMWmtUEOZyoU51QXL7msf/3I1mrcm3dm4bh2rM9ZQa1/goxQYqMJaxnCh73GUqExBXfALJ6H0gAPmoOvRcRIEVfzk1kHNqKWTn1VDPxhBniDOq38rjiONVer/Eecc+lpK2s0cSuSFqmaZP/aAdjAbLRjvs1lo4ca/J/SQ0co+lfbnk2CaOFFRm7YWo9FkXMGhpGdmG72LXVlpVQ7rMeFtPx7bhAuxQ4HyHE6SBNZxrPFKSfwOsxO2ubrzrcInkArayxovNTEBa5e7YNzyjV2tE7/ZfK2O4LPfsfDXzOos+mvTX66/5JhRiJIHOV7HEdwlz8MxCe4NKFmSHD3AcfR0irVpv1/DrNs/AWT/Ew==</diagram></mxfile>
38 changes: 38 additions & 0 deletions example/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
site_name: Test site
site_description: Mkdocs tests site
site_author: Lukas Holota
site_url: https://www.example.com/

nav:
- Index: index.md

# Configuration
theme:
name: material
language: en
palette:
primary: deep orange
accent: deep orange
font:
text: Roboto
code: Roboto Mono

plugins:
- drawio-exporter:
# Diagrams are cached to speed up site generation. The default path is
# drawio-exporter, relative to the documentation directory.
cache_dir: 'drawio-exporter'
# Path to the Draw.io executable:
# * drawio on Linux
# * draw.io on macOS
# * or draw.io.exe on Windows
# We'll look for it on your system's PATH, then default installation
# paths. If we can't find it we'll warn you.
drawio_executable: null
# Additional Draw.io CLI args
drawio_args:
- --no-sandbox
# Output format (see draw.io --help | grep format)
format: svg
# Glob pattern for matching source files
sources: '*.drawio'
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "homecentr-$$IMAGE_NAME$$",
"name": "homecentr-mkdocs",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/homecentr/docker-$$IMAGE_NAME$$.git"
"url": "git+https://github.com/homecentr/docker-mkdocs.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/homecentr/docker-$$IMAGE_NAME$$/issues"
"url": "https://github.com/homecentr/docker-mkdocs/issues"
},
"homepage": "https://github.com/homecentr/docker-$$IMAGE_NAME$$#readme"
"homepage": "https://github.com/homecentr/docker-mkdocs#readme"
}
6 changes: 0 additions & 6 deletions tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>docker-$$IMAGE_NAME$$-tests</name>
<name>docker-mkdocs-tests</name>
<comment>Project tests created by Buildship.</comment>
<projects>
</projects>
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'docker-$$IMAGE_NAME$$-tests'
rootProject.name = 'docker-mkdocs-tests'

43 changes: 40 additions & 3 deletions tests/src/test/java/ContainerTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public abstract class ContainerTestBase {
private static final Logger logger = LoggerFactory.getLogger(ContainerTestBase.class);

private static GenericContainer _container;

@BeforeClass
public static void setUp() {
String dockerImageTag = System.getProperty("image_tag", "homecentr/$$IMAGE_NAME$$");
public static void setUp() throws IOException {
String dockerImageTag = System.getProperty("image_tag");

logger.info("Tested Docker image tag: {}", dockerImageTag);

clearExporterCache();

_container = new GenericContainer<>(dockerImageTag)
.waitingFor(Wait.forHealthcheck());
.withFileSystemBind(getExamplesPath(), "/docs")
.waitingFor(Wait.forLogMessage("(.*)Serving on http:https://0\\.0\\.0\\.0:8000(.*)", 1));

_container.start();
_container.followOutput(new Slf4jLogConsumer(logger));
Expand All @@ -33,4 +41,33 @@ public static void cleanUp() {
protected GenericContainer getContainer() {
return _container;
}

protected static String getExamplesPath() {
Path result = Paths.get(System.getProperty("user.dir"), "../example").normalize();

System.out.println("PATH=" + result.toString());

return result.toString();
}

protected static Path getExporterCachePath() {
return Paths.get(getExamplesPath(), "docs", "drawio-exporter");
}

protected static void clearExporterCache() throws IOException {
File directory = new File(getExporterCachePath().toString());

if(!directory.exists()) {
return;
}

File[] allContents = directory.listFiles();
if (allContents != null) {
for (File file : allContents) {
file.delete();
}
}

directory.delete();
}
}
15 changes: 15 additions & 0 deletions tests/src/test/java/MkDocsContainerShould.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.assertTrue;

public class MkDocsContainerShould extends ContainerTestBase {
@Test
public void generateSvg() {
File cacheDir = new File(getExporterCachePath().toString());
File[] files = cacheDir.listFiles();

assertTrue(files.length > 0);
}
}
Empty file added tests/src/test/resources/dummy
Empty file.

0 comments on commit beedef9

Please sign in to comment.