Merge pull request #421 from bastienwirtz/docker-rework

Docker rework
This commit is contained in:
Bastien Wirtz 2022-04-30 15:42:31 +02:00 committed by GitHub
commit 7e48e099aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 54 deletions

View File

@ -12,22 +12,28 @@ RUN yarn build
# production stage # production stage
FROM alpine:3.15 FROM alpine:3.15
ENV USER darkhttpd ENV GID 1000
ENV GROUP darkhttpd ENV UID 1000
ENV GID 911
ENV UID 911
ENV PORT 8080 ENV PORT 8080
ENV SUBFOLDER "/_"
ENV INIT_ASSETS 1
RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \ RUN addgroup -S lighttpd -g ${GID} && adduser -D -S -u ${UID} lighttpd lighttpd && \
apk add -U --no-cache su-exec darkhttpd apk add -U --no-cache lighttpd
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/ WORKDIR /www
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
COPY lighttpd.conf /lighttpd.conf
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
COPY --from=build-stage --chown=${UID}:${GID} /app/dist /www/
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
USER ${UID}:${GID}
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
EXPOSE ${PORT} EXPOSE ${PORT}
VOLUME /www/assets VOLUME /www/assets
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]

View File

@ -21,23 +21,27 @@ FROM arm32v7/alpine:3.11
COPY --from=qemu qemu-arm-static /usr/bin/ COPY --from=qemu qemu-arm-static /usr/bin/
ENV USER darkhttpd ENV USER lighttpd
ENV GROUP darkhttpd ENV GROUP lighttpd
ENV GID 911 ENV GID 911
ENV UID 911 ENV UID 911
ENV PORT 8080 ENV PORT 8080
ENV SUBFOLDER "/_"
RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \ RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \
apk add -U --no-cache darkhttpd su-exec && \ apk add -U --no-cache lighttpd && \
rm /usr/bin/qemu-arm-static rm /usr/bin/qemu-arm-static
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/ WORKDIR /www
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
COPY entrypoint.sh /entrypoint.sh
COPY lighttpd.conf /lighttpd.conf
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/
USER ${USER}
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
EXPOSE ${PORT} EXPOSE ${PORT}
VOLUME /www/assets VOLUME /www/assets
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
CMD ["lighttpd", "-D", "-f", "/lighttpd.conf"]

View File

@ -21,23 +21,27 @@ FROM arm64v8/alpine:3.11
COPY --from=qemu qemu-aarch64-static /usr/bin/ COPY --from=qemu qemu-aarch64-static /usr/bin/
ENV USER darkhttpd ENV USER lighttpd
ENV GROUP darkhttpd ENV GROUP lighttpd
ENV GID 911 ENV GID 911
ENV UID 911 ENV UID 911
ENV PORT 8080 ENV PORT 8080
ENV SUBFOLDER "/_"
RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \ RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \
apk add -U --no-cache darkhttpd su-exec && \ apk add -U --no-cache lighttpd && \
rm /usr/bin/qemu-aarch64-static rm /usr/bin/qemu-aarch64-static
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/ WORKDIR /www
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
COPY entrypoint.sh /entrypoint.sh
COPY lighttpd.conf /lighttpd.conf
COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/
USER ${USER}
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
EXPOSE ${PORT} EXPOSE ${PORT}
VOLUME /www/assets VOLUME /www/assets
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
CMD ["lighttpd", "-D", "-f", "/lighttpd.conf"]

View File

@ -71,8 +71,6 @@ See [documentation](docs/configuration.md) for information about the configurati
### Using docker ### Using docker
To launch container:
```sh ```sh
docker run -d \ docker run -d \
-p 8080:8080 \ -p 8080:8080 \
@ -81,12 +79,19 @@ docker run -d \
b4bz/homer:latest b4bz/homer:latest
``` ```
Default assets will be automatically installed in the `/www/assets` directory. Use `UID` and/or `GID` env var to change the assets owner (`docker run -e "UID=1000" -e "GID=1000" [...]`). Environment variables:
* **`INIT_ASSETS`** (default: `1`)
Install exemple configuration file & assets (favicons, ...) to help you get started.
* **`SUBFOLDER`** (default: `null`)
If you would like to host Homer in a subfolder, (ex: *http://my-domain/**homer***), set this to the subfolder path (ex `/homer`).
### Using docker-compose ### Using docker-compose
The `docker-compose.yml` file must be edited to match your needs. The `docker-compose.yml` file must be edited to match your needs.
Set the port and volume (equivalent to `-p` and `-v` arguments): You probably want to set the port mapping and volume binding (equivalent to `-p` and `-v` arguments):
```yaml ```yaml
volumes: volumes:
@ -95,21 +100,13 @@ ports:
- 8080:8080 - 8080:8080
``` ```
To launch container: Then launch the container:
```sh ```sh
cd /path/to/docker-compose.yml cd /path/to/docker-compose.yml/
docker-compose up -d docker-compose up -d
``` ```
Default assets will be automatically installed in the `/www/assets` directory. Use `UID` and/or `GID` env var to change the assets owner, also in `docker-compose.yml`:
```yaml
environment:
- UID=1000
- GID=1000
```
### Using the release tarball (prebuilt, ready to use) ### Using the release tarball (prebuilt, ready to use)
Download and extract the latest release (`homer.zip`) from the [release page](https://github.com/bastienwirtz/homer/releases), rename the `assets/config.yml.dist` file to `assets/config.yml`, and put it behind a web server. Download and extract the latest release (`homer.zip`) from the [release page](https://github.com/bastienwirtz/homer/releases), rename the `assets/config.yml.dist` file to `assets/config.yml`, and put it behind a web server.

View File

@ -10,7 +10,6 @@ services:
- /your/local/assets/:/www/assets - /your/local/assets/:/www/assets
ports: ports:
- 8080:8080 - 8080:8080
#environment: user: 1000:1000 # default
# - UID=1000 environment:
# - GID=1000 - INIT_ASSETS=1 # default
restart: unless-stopped

View File

@ -1,15 +1,18 @@
#!/bin/sh #!/bin/sh
# Ensure default assets are present. PERMISSION_ERROR="Check assets directory permissions & docker user or skip default assets install by setting the INIT_ASSETS env var to 0"
while true; do echo n; done | cp -Ri /www/default-assets/* /www/assets/ &> /dev/null
# Ensure compatibility with previous version (config.yml was in the root directory) # Default assets & exemple configuration installation if possible.
if [ -f "/www/config.yml" ]; then if [[ "${INIT_ASSETS}" == "1" ]] && [[ ! -f "/www/config.yml" ]]; then
yes n | cp -i /www/config.yml /www/assets/ &> /dev/null echo "No configuration found, installing default config & assets"
if [[ ! -w "/www/assets/" ]]; then echo "Assets directory not writable. $PERMISSION_ERROR" && exit 1; fi
while true; do echo n; done | cp -Ri /www/default-assets/* /www/assets/ &> /dev/null
if [[ $? -ne 0 ]]; then echo "Fail to copy default assets. $PERMISSION_ERROR" && exit 1; fi
yes n | cp -i /www/default-assets/config.yml.dist /www/assets/config.yml &> /dev/null
if [[ $? -ne 0 ]]; then echo "Fail to copy default config file. $PERMISSION_ERROR" && exit 1; fi
fi fi
# Install default config if no one is available. echo "Starting webserver"
yes n | cp -i /www/default-assets/config.yml.dist /www/assets/config.yml &> /dev/null lighttpd -D -f /lighttpd.conf
chown -R $UID:$GID /www/assets
exec su-exec $UID:$GID darkhttpd /www/ --no-listing --port "$PORT"

10
lighttpd.conf Normal file
View File

@ -0,0 +1,10 @@
include "/etc/lighttpd/mime-types.conf"
server.port = env.PORT
server.modules = ( "mod_alias" )
server.username = "lighttpd"
server.groupname = "lighttpd"
server.document-root = "/www"
alias.url = ( env.SUBFOLDER => "/www" )
server.indexfiles = ("index.html")
server.follow-symlink = "enable"

View File

@ -18,7 +18,10 @@
</a> </a>
<i v-if="config.icon" :class="config.icon"></i> <i v-if="config.icon" :class="config.icon"></i>
</div> </div>
<div class="dashboard-title"> <div
class="dashboard-title"
:class="{ 'no-logo': !config.icon || !config.logo }"
>
<span class="headline">{{ config.subtitle }}</span> <span class="headline">{{ config.subtitle }}</span>
<h1>{{ config.title }}</h1> <h1>{{ config.title }}</h1>
</div> </div>
@ -61,7 +64,7 @@
@network-status-update="offline = $event" @network-status-update="offline = $event"
/> />
<GetStarted v-if="loaded && !services" /> <GetStarted v-if="configurationNeeded" />
<div v-if="!offline"> <div v-if="!offline">
<!-- Optional messages --> <!-- Optional messages -->
@ -168,6 +171,7 @@ export default {
data: function () { data: function () {
return { return {
loaded: false, loaded: false,
configNotFound: false,
config: null, config: null,
services: null, services: null,
offline: false, offline: false,
@ -177,6 +181,11 @@ export default {
showMenu: false, showMenu: false,
}; };
}, },
computed: {
configurationNeeded: function () {
return (this.loaded && !this.services) || this.configNotFound;
},
},
created: async function () { created: async function () {
this.buildDashboard(); this.buildDashboard();
window.onhashchange = this.buildDashboard; window.onhashchange = this.buildDashboard;
@ -228,6 +237,11 @@ export default {
return; return;
} }
if (response.status == 404) {
this.configNotFound = true;
return {};
}
if (!response.ok) { if (!response.ok) {
throw Error(`${response.statusText}: ${response.body}`); throw Error(`${response.statusText}: ${response.body}`);
} }

View File

@ -104,6 +104,10 @@ body {
.dashboard-title { .dashboard-title {
padding: 6px 0 0 80px; padding: 6px 0 0 80px;
&.no-logo {
padding-left: 0;
}
} }
.first-line { .first-line {

View File

@ -6,7 +6,7 @@
<p> <p>
<a <a
class="button is-primary mt-5 has-text-weight-bold" class="button is-primary mt-5 has-text-weight-bold"
href="https://github.com/bastienwirtz/homer/blob/main/README.md#getting-started" href="https://github.com/bastienwirtz/homer/blob/main/docs/configuration.md#configuration"
target="_blank" target="_blank"
> >
Get started Get started