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

Add docker file for creating docker container for divoom-gateway. #59

Merged
merged 1 commit into from
Aug 5, 2022
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
13 changes: 13 additions & 0 deletions build/azure-pipeline/workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ stages:
BUILD_PROFILE: "release"
BUILD_ARCH: $(target_arch)

- script: just pack-docker-all
displayName: Pack divoom docker package sources
condition: and(succeeded(), eq(variables['target_os'], 'linux'))
env:
BUILD_PROFILE: "release"
BUILD_ARCH: $(target_arch)

#
# Copy all files to publish folder
#
Expand Down Expand Up @@ -345,6 +352,12 @@ stages:
env:
BUILD_VERSION: $(Build.Version)

- script: just pack-docker
displayName: Pack docker package for release
workingDirectory: '$(System.DefaultWorkingDirectory)/r12f.divoom'
env:
BUILD_VERSION: $(Build.Version)

- script: just prepare-crate-io-release
displayName: Prepare Crate.IO release
workingDirectory: '$(System.DefaultWorkingDirectory)/r12f.divoom'
Expand Down
47 changes: 47 additions & 0 deletions build/package-templates/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Dockerfile for running divoom-gateway container.
#
# To create the container and specify the device to control on the runtime, we can use the following command to specify the environment variables:
#
# docker container create -e DEVICE_ADDRESS=192.168.0.164 <image-name>
#
# To enable debug logs, we can add this additional environment variable in the command line: -e RUST_LOG=debug
#


#
# Global definitions
#

# It is always better to have a shell and support for basic tools, such as wget and etc.
# This only adds ~1.2MB to the final image, which worths every single penny.
FROM busybox

# Environment variables
ENV DEVICE_ADDRESS=127.0.0.1
ENV GATEWAY_ADDRESS=0.0.0.0
ENV GATEWAY_PORT=20821

#
# Build container
#

# Install fonts
RUN mkdir -p /usr/share/fonts/truetype/

COPY *.ttf /
RUN install -m644 *.ttf /usr/share/fonts/truetype/
RUN rm ./*.ttf

# Copy gateway binary
COPY divoom-gateway /

#
# Runtime
#

# Expose port
EXPOSE $GATEWAY_PORT/tcp

# Entrypoint
CMD ["sh", "-c", "./divoom-gateway ${DEVICE_ADDRESS} -s ${GATEWAY_ADDRESS} -p ${GATEWAY_PORT}"]
10 changes: 10 additions & 0 deletions build/post-build/post-build.justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RELEASE_GITHUB_FOLDER := RELEASE_FOLDER + "/github"
RELEASE_CHOCO_FOLDER := RELEASE_FOLDER + "/choco"
RELEASE_SCOOP_FOLDER := RELEASE_FOLDER + "/scoop"
RELEASE_SNAP_FOLDER := RELEASE_FOLDER + "/snap"
RELEASE_DOCKER_FOLDER := RELEASE_FOLDER + "/docker"

#
# Preparation tasks
Expand Down Expand Up @@ -112,6 +113,15 @@ pack-snap:

Get-ChildItem ./{{BUILD_FOLDER_PREFIX}}*/*/snap-source/* -Attributes Directory | Copy-Item -Destination "{{RELEASE_SNAP_FOLDER}}" -Recurse -PassThru

#
# Pack snap
#
pack-docker:
if (Test-Path "{{RELEASE_DOCKER_FOLDER}}") { Remove-Item -Path "{{RELEASE_DOCKER_FOLDER}}" -Recurse -Force }
New-Item -ItemType Directory -Path "{{RELEASE_DOCKER_FOLDER}}" -Force | Out-Null

Get-ChildItem ./{{BUILD_FOLDER_PREFIX}}*/*/docker-source/* -Attributes Directory | Copy-Item -Destination "{{RELEASE_DOCKER_FOLDER}}" -Recurse -PassThru

#
# Prepare packages for crate.io release
#
Expand Down
16 changes: 16 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ pack-snap PACKAGE="divoom_cli":
"{{PUBLISH_DIR}}/{{PACKAGE}}/template-parameters" \
"{{PUBLISH_CHECKSUMS_DIR}}"

pack-docker-all:
just pack-docker divoom_gateway

pack-docker PACKAGE="divoom_gateway":
@Write-Host "Current invocation directory: {{invocation_directory()}}"

if (Test-Path "{{PUBLISH_DIR}}/{{PACKAGE}}/docker-source") { Remove-Item -Path "{{PUBLISH_DIR}}/{{PACKAGE}}/docker-source" -Recurse -Force }
New-Item -ItemType Directory -Path "{{PUBLISH_DIR}}/{{PACKAGE}}/docker-source/{{replace(PACKAGE, '_', '-')}}.{{BUILD_ARCH}}" -Force | Out-Null

Copy-Item -Path "{{PUBLISH_DIR}}/{{PACKAGE}}/bin/*" -Destination "{{PUBLISH_DIR}}/{{PACKAGE}}/docker-source/{{replace(PACKAGE, '_', '-')}}.{{BUILD_ARCH}}"

just eval-template "{{justfile_directory()}}/build/package-templates/docker/Dockerfile" \
"{{PUBLISH_DIR}}/{{PACKAGE}}/docker-source/{{replace(PACKAGE, '_', '-')}}.{{BUILD_ARCH}}/Dockerfile" \
"{{PUBLISH_DIR}}/{{PACKAGE}}/template-parameters" \
"{{PUBLISH_CHECKSUMS_DIR}}"

#
# Publish tasks:
#
Expand Down