-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 17d851c
Showing
11 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Create docker image from python3.9-slim | ||
FROM python:3.9-slim | ||
|
||
# Create python venv and add it to PATH | ||
RUN python -m venv /ledfx/venv \ | ||
&& python -m pip install -U pip wheel setuptools | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
|
||
# Install dependencies and ledfx, remove uneeded packages | ||
# | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
&& apt-get install -y \ | ||
# alsa-utils \ | ||
libatlas3-base \ | ||
portaudio19-dev \ | ||
# pulseaudio \ | ||
python3-dev \ | ||
&& pip install ledfx-dev \ | ||
&& apt-get purge -y gcc python3-dev \ | ||
&& apt-get clean -y \ | ||
&& apt-get autoremove -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Add user `ledfx` and create home folder | ||
RUN useradd --create-home ledfx | ||
# Set the working directory in the container | ||
WORKDIR /home/ledfx | ||
USER ledfx | ||
|
||
# Expose port 8888 for web server and 5353 for mDNS discovery | ||
EXPOSE 8888/tcp | ||
EXPOSE 5353/udp | ||
ENTRYPOINT [ "ledfx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
### Create docker image from python3.9-slim | ||
# | ||
# Set up base venv image to start the build | ||
FROM python:3.9-slim AS venv-image | ||
# Create python venv and add it to PATH | ||
RUN python -m venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
RUN python -m pip install --upgrade pip wheel setuptools | ||
# Install dependencies and ledfx, remove uneeded packages | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
alsa-utils \ | ||
libatlas3-base \ | ||
portaudio19-dev \ | ||
pulseaudio \ | ||
&& apt-get clean -y \ | ||
&& apt-get autoremove -y | ||
|
||
### Create docker image from venv-image as compile-image to speed up builds | ||
# | ||
FROM venv-image AS compile-image | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
git \ | ||
libc-dev \ | ||
nodejs \ | ||
npm \ | ||
python3-dev | ||
|
||
### Create docker image from compile-image to pull and build from github | ||
# | ||
FROM compile-image AS build-image | ||
COPY --from=venv-image /ledfx/venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
RUN pip install git+https://github.com/LedFx/LedFx@dev | ||
|
||
# Create docker image from venv-image to build dist-image | ||
# | ||
FROM venv-image AS dist-image | ||
|
||
COPY --from=build-image /ledfx/venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
|
||
RUN rm -rf /var/lib/apt/lists/* \ | ||
useradd --create-home ledfx --groups audio | ||
WORKDIR /home/ledfx | ||
USER ledfx | ||
|
||
EXPOSE 8888/tcp | ||
EXPOSE 5353/udp | ||
ENTRYPOINT [ "ledfx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Create docker image from arm32v7/python:3.9-slim | ||
# This image serves as the base venv image | ||
|
||
############### VENV IMAGE ############### | ||
FROM arm32v7/python:3.9-slim AS venv-image | ||
# Create python venv and add it to PATH | ||
RUN python -m venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
RUN python -m pip install --upgrade pip wheel setuptools | ||
# Install dependencies and ledfx, remove uneeded packages | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
alsa-utils \ | ||
libatlas3-base \ | ||
portaudio19-dev \ | ||
pulseaudio \ | ||
&& apt-get clean -y \ | ||
&& apt-get autoremove -y | ||
|
||
############### COMPILE IMAGE ############### | ||
FROM venv-image AS compile-image | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
git \ | ||
libc-dev \ | ||
nodejs \ | ||
npm \ | ||
python3-dev | ||
|
||
########## BUILD IMAGE ########## | ||
FROM compile-image AS build-image | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
RUN pip install git+https://github.com/LedFx/LedFx@dev | ||
|
||
|
||
# Create arm32v7/python:3.9-slim - Dist Image | ||
# This image copies /ledfx/venv from build-image for a smaller final image | ||
|
||
############### DIST IMAGE ############### | ||
FROM venv-image AS dist-image | ||
|
||
COPY --from=build-image /ledfx/venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
RUN rm -rf /var/lib/apt/lists/* \ | ||
useradd --create-home ledfx --groups audio | ||
# Set the working directory in the container | ||
WORKDIR /home/ledfx | ||
USER ledfx | ||
# Expose port 8888 for web server | ||
EXPOSE 8888/tcp | ||
EXPOSE 5353/udp | ||
ENTRYPOINT [ "ledfx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Create docker image from python3.7-slim | ||
FROM ledfx-venv | ||
COPY --from=ledfx-compile /ledfx/venv /ledfx/venv | ||
# ENV PATH="/ledfx/venv/bin:$PATH" | ||
|
||
# Remove uneeded packages | ||
RUN rm -rf /var/lib/apt/lists/* | ||
|
||
# Add user `ledfx` and create home folder | ||
RUN useradd --create-home ledfx | ||
# Set the working directory in the container | ||
WORKDIR /home/ledfx | ||
USER ledfx | ||
|
||
# Expose port 8888 for web server and 5353 for mDNS discovery | ||
EXPOSE 8888/tcp | ||
EXPOSE 5353/udp | ||
ENTRYPOINT [ "ledfx"] | ||
#CMD ["--host 0.0.0.0","--port 8888"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### Create docker image from venv-image as compile-image to speed up builds | ||
# | ||
FROM ledfx-venv AS compile-image | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
WORKDIR /ledfx | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
libc-dev | ||
RUN pip install ledfx-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
### Create docker image from python3.7-slim | ||
# | ||
# Set up base venv image to start the build | ||
FROM python:3.7-slim AS venv-image | ||
# Create python venv and add it to PATH | ||
RUN python -m venv /ledfx/venv | ||
ENV PATH="/ledfx/venv/bin:$PATH" | ||
# Install dependencies and ledfx, remove uneeded packages | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
alsa-utils \ | ||
# libasound2 \ | ||
# libasound2-plugins \ | ||
portaudio19-dev \ | ||
pulseaudio \ | ||
&& apt-get clean -y \ | ||
&& apt-get autoremove -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Edu_Coder | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# ledfx-docker | ||
|
||
An attempt at running LedFX inside a docker container | ||
|
||
## How these files work | ||
|
||
### **Dockerfile:** | ||
|
||
This file uses the python:3.7-slim image: | ||
|
||
* It first creates a python virtual environment /ledfx/venv | ||
* "activate" the python venv by adding it to the `PATH` | ||
* Install compile and run dependencies with `apt-get` | ||
* Install ledfx-dev from `pip` | ||
* Purge compile dependencies with `apt-get`, `clean` and `autoremove` | ||
* Add ledfx user and create a home folder | ||
* Set `WORKDIR` to ledfx home directory and change `USER` to ledfx | ||
* `EXPOSE` ports 8888 and 5353 | ||
* Launch ledfx | ||
|
||
How to use: `docker build -t ledfx .` | ||
|
||
### **Dockerfile-2stage-1:** | ||
|
||
This file uses the python:3.7-slim image: | ||
|
||
1. Create a "compile-image" | ||
|
||
* Set `WORKDIR` to /ledfx | ||
* Install compile dependencies with `apt-get` | ||
* Clone ledfx dev branch into /ledfx using `git clone` | ||
* cd to /ledfx/frontend | ||
* Install `yarn` and build the frontend | ||
* cd to /ledfx | ||
* Create a python venv /ledfx/venv and "activate" it by adding it to the `PATH` | ||
* Install ledfx-dev from source using `pip` | ||
|
||
2. Create a "build-image" | ||
|
||
* `COPY` /ledfx/venv from "compile-image" to current image | ||
* Activate the venv by adding it to the `PATH` | ||
* Install run dependencies with `apt-get` | ||
* Add ledfx user and create a home folder | ||
* Set `WORKDIR` to ledfx home directory and change `USER` to ledfx | ||
* `EXPOSE` ports 8888 and 5353 | ||
* Launch ledfx | ||
|
||
How to use: `docker build -t ledfx-2stage -f Dockerfile-2stage-1 .` | ||
|
||
### **Dockerfile-4stage:** | ||
|
||
This file uses docker's multi-stage build technique to speed up the build process using the cache and cut down the overall size of the final image. | ||
|
||
While all 4 images will be built initially, we can significantly cut down the build times by using the cached images that won't change regularly. Docker will use the cache up until the point in the Dockerfile that it detects a change. Any lines after that change will be build from scratch. | ||
|
||
By creating the venv and compile images in the beggining of the Dockerfile, we can be fairly certain that these dependencies won't change regularly. This cuts down the time required to build by skipping the dependency installation process. | ||
|
||
1. Create "venv-image" | ||
|
||
* Create a python venv /ledfx/venv and "activate" it by adding it to the `PATH` | ||
* Install compile and run dependencies with `apt-get` | ||
|
||
2. Create "compile-image" from "venv-image" | ||
|
||
* Install build dependencies with `apt-get` | ||
|
||
3. Create "build-image" from "compile-image" | ||
|
||
* `COPY` /ledfx/venv from "venv-image" to current image | ||
* Activate the venv by adding it to the `PATH` | ||
* Set `WORKDIR` to /ledfx-git | ||
* Clone ledfx dev branch into /ledfx-git using `git clone` | ||
* `cd` to /ledfx/frontend | ||
* Install `yarn` and build the frontend | ||
* `cd` to /ledfx | ||
* Create a python venv /ledfx/venv and "activate" it by adding it to the `PATH` | ||
* Install ledfx-dev from source using `pip` | ||
|
||
4. Create "dist-image" from "venv-image" | ||
|
||
* `COPY` /ledfx/venv from "build-image" to current image | ||
* Activate the venv by adding it to the `PATH` | ||
* Remove all lists from /var/lib/apt/lists/ | ||
* Add ledfx user and create a home folder | ||
* Set `WORKDIR` to ledfx home directory and change `USER` to ledfx | ||
* `EXPOSE` ports 8888 and 5353 | ||
* Launch ledfx | ||
|
||
How to use: `docker build -t ledfx-4stage -f Dockerfile-4stage .` | ||
|
||
### **Dockerfile.venv, Dockerfile.compile, Dockerfile.build:** | ||
|
||
These files take a similar approach to Dockerfile-4stage. They differ in the fact that they use 3 independent Dockerfile's to achieve the same results. I'm not sure if this is significant, but I was learning how to create Dockerfile's when I wrote these so I decided to try it out. | ||
|
||
1. Dockerfile.venv | ||
|
||
* Create "venv-image" from python:3.7-slim | ||
* Create a python venv /ledfx/venv and "activate" it by adding it to the `PATH` | ||
* Install run dependencies with `apt-get` | ||
|
||
How to use: `docker build -t thatdonfc/ledfx-venv -f Dockerfile.venv .` | ||
|
||
2. Dockerfile.compile | ||
|
||
* Create "compile-image" from "venv-image" named thatdonfc/ledfx-venv | ||
* Activate the venv by adding it to the `PATH` | ||
* Install build dependencies with `apt-get` | ||
* Install ledfx-dev with `pip` | ||
|
||
How to use: `docker build -t thatdonfc/ledfx-compile -f Dockerfile.compile .` | ||
|
||
3. Dockerfile.build | ||
|
||
* Create build image from "venv-image" named thatdonfc/ledfx-venv | ||
* `COPY` /ledfx/venv from "compile-image" named thatdonfc/ledfx-compile | ||
* Remove all lists from /var/lib/apt/lists/ | ||
* Add ledfx user and create a home folder | ||
* Set `WORKDIR` to ledfx home directory and change `USER` to ledfx | ||
* `EXPOSE` ports 8888 and 5353 | ||
* Launch ledfx | ||
|
||
How to use: `docker build -t thatdonfc/ledfx-build -f Dockerfile.build .` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3.4' | ||
|
||
services: | ||
ledfxdev4: | ||
image: ledfxdev4 | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile-4stage | ||
entrypoint: ledfx --host 0.0.0.0 -p 8888 | ||
hostname: ledfx | ||
restart: unless-stopped | ||
ports: | ||
- 8888:8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '.github/worflows/*publish*' | ||
- 'Dockerfile' | ||
- '!ledfx*/**' | ||
- '!*-*' | ||
- '!*.*' | ||
|
||
jobs: | ||
ledfx: | ||
env: | ||
IMAGE_NAME: ledfx | ||
name: Build LedFx on ubuntu-latest | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build ledfx | ||
run: | | ||
docker build --file Dockerfile --tag ledfx . | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
Oops, something went wrong.