From 35815ed17c18718a16b1f92b24012663b742f793 Mon Sep 17 00:00:00 2001 From: Thirsty2 Date: Tue, 13 Oct 2020 11:51:16 -0700 Subject: [PATCH 1/5] Add Dockerfile to build container using the installer. --- Dockerfile.use-installer | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Dockerfile.use-installer diff --git a/Dockerfile.use-installer b/Dockerfile.use-installer new file mode 100644 index 0000000..4a0b648 --- /dev/null +++ b/Dockerfile.use-installer @@ -0,0 +1,42 @@ +ARG IMAGE="python:3-slim-buster" + +#--- +# Place anything that is common to both the build and execution environment in base +# +FROM $IMAGE AS base + +RUN apt-get update -qq \ + && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + ca-certificates \ + git \ + make \ + wget \ + && apt-get autoclean && apt-get clean && apt-get -y autoremove \ + && update-ca-certificates \ + && rm -rf /var/lib/apt/lists + +RUN wget https://github.com/im-tomu/fomu-toolchain/releases/download/v1.5.6/fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ + tar -xvf fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ + rm fomu-toolchain-linux_x86_64-v1.5.6.tar.gz + +ENV PATH=/fomu-toolchain-linux_x86_64-v1.5.6/bin:$PATH + +FROM base as release-candidate + +RUN adduser --disabled-password fomu +USER fomu +WORKDIR /home/fomu + +# Commented section to show where we would run tests in an image layer identical to the release candidate +# without polluting the release candidate with test results. Uncomment the following and add tests: +# FROM release-candidate as test-release-candidate +# Ideally we would run some tests here + +FROM release-candidate as fomu-toolchain + +# Below are some sample commands to build and run a docker images. +# +# docker build -f Dockerfile.use-installer . -t fomu-toolchain +# +# docker run -it -v $(pwd):/home/fomu fomu-toolchain bash + From 4315d88a777645e5b0ef5bb70863a5c387454fea Mon Sep 17 00:00:00 2001 From: Thirsty2 Date: Tue, 13 Oct 2020 22:56:59 -0700 Subject: [PATCH 2/5] dfu-util works, but can't yet unplug and replug fomu. --- Dockerfile.use-installer | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dockerfile.use-installer b/Dockerfile.use-installer index 4a0b648..e75684f 100644 --- a/Dockerfile.use-installer +++ b/Dockerfile.use-installer @@ -9,6 +9,7 @@ RUN apt-get update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ ca-certificates \ git \ + libusb-1.0-0 \ make \ wget \ && apt-get autoclean && apt-get clean && apt-get -y autoremove \ @@ -23,9 +24,13 @@ ENV PATH=/fomu-toolchain-linux_x86_64-v1.5.6/bin:$PATH FROM base as release-candidate -RUN adduser --disabled-password fomu -USER fomu -WORKDIR /home/fomu +ENV USER=fomu +RUN adduser --disabled-password ${USER} + +RUN usermod -a -G plugdev ${USER} +# COPY 99-fomu.rules /etc/udev/rules.d/99-fomu.rules +USER ${USER} +WORKDIR /home/${USER} # Commented section to show where we would run tests in an image layer identical to the release candidate # without polluting the release candidate with test results. Uncomment the following and add tests: @@ -39,4 +44,8 @@ FROM release-candidate as fomu-toolchain # docker build -f Dockerfile.use-installer . -t fomu-toolchain # # docker run -it -v $(pwd):/home/fomu fomu-toolchain bash - +# +# The --privileged param may be used to allow access to usb devices +# but it allows access to much more, and may be a security risk. +# There may be a better way to allow dfu-util to run +# docker run -it -v $(pwd):/home/fomu --privileged fomu-toolchain bash From e548265c3dfeff81fb3770673fd56364da17c6cf Mon Sep 17 00:00:00 2001 From: Thirsty2 Date: Wed, 14 Oct 2020 16:44:36 -0700 Subject: [PATCH 3/5] Moved docker files to dockerfiles folder --- dockerfiles/99-fomu.rules | 1 + .../Dockerfile.use-installer | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 dockerfiles/99-fomu.rules rename Dockerfile.use-installer => dockerfiles/Dockerfile.use-installer (52%) diff --git a/dockerfiles/99-fomu.rules b/dockerfiles/99-fomu.rules new file mode 100644 index 0000000..d019e65 --- /dev/null +++ b/dockerfiles/99-fomu.rules @@ -0,0 +1 @@ +SUBSYSTEM=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="5bf0", MODE="0664", GROUP="plugdev" diff --git a/Dockerfile.use-installer b/dockerfiles/Dockerfile.use-installer similarity index 52% rename from Dockerfile.use-installer rename to dockerfiles/Dockerfile.use-installer index e75684f..c92186b 100644 --- a/Dockerfile.use-installer +++ b/dockerfiles/Dockerfile.use-installer @@ -16,26 +16,40 @@ RUN apt-get update -qq \ && update-ca-certificates \ && rm -rf /var/lib/apt/lists +# FROM base as builder +# Install necessary tools and source code and build from source here for ci/cd +# If any build or test return a non-zero exit code, the docker build stops +# with an error, which is nice for ci/cd like github actions. + +# FROM builder as test-builder +# Run regression tests on binaries built from source here + +# FROM builder as installer +# create an installer from the binaries built from source here + +FROM base as release-candidate +# use --copy-from builder to copy binaries into the right place here if built from source, +# or copy the installer with --copy-from installer +# or use the pre-built released installer as we do here: RUN wget https://github.com/im-tomu/fomu-toolchain/releases/download/v1.5.6/fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ tar -xvf fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ rm fomu-toolchain-linux_x86_64-v1.5.6.tar.gz - + ENV PATH=/fomu-toolchain-linux_x86_64-v1.5.6/bin:$PATH -FROM base as release-candidate - ENV USER=fomu RUN adduser --disabled-password ${USER} - +# RUN groupadd plugdev # error - already exists RUN usermod -a -G plugdev ${USER} -# COPY 99-fomu.rules /etc/udev/rules.d/99-fomu.rules +COPY 99-fomu.rules /etc/udev/rules.d/99-fomu.rules +# RUN udevadm control --reload-rules +# RUN udevadm trigger USER ${USER} WORKDIR /home/${USER} -# Commented section to show where we would run tests in an image layer identical to the release candidate -# without polluting the release candidate with test results. Uncomment the following and add tests: # FROM release-candidate as test-release-candidate -# Ideally we would run some tests here +# Run any tests on final image here + FROM release-candidate as fomu-toolchain @@ -47,5 +61,11 @@ FROM release-candidate as fomu-toolchain # # The --privileged param may be used to allow access to usb devices # but it allows access to much more, and may be a security risk. -# There may be a better way to allow dfu-util to run +# There may be a better way to allow dfu-util and wishbone-tool to run # docker run -it -v $(pwd):/home/fomu --privileged fomu-toolchain bash +# +# On my old laptop running ubuntu 20.04, I need to re-run the docker +# container after using dfu-util in order to use it again or to use +# wishbone-tool. Perhaps I am missing a dependency here? I installed +# udev and dfu-util above just to see if that would pull in something +# I missed, but I don't think it helped. I removed them again. From d08681b2d73940b6e9434a2b80dcefa0bd3101a6 Mon Sep 17 00:00:00 2001 From: Thirsty2 Date: Wed, 14 Oct 2020 16:57:09 -0700 Subject: [PATCH 4/5] Fixed some comments. --- dockerfiles/Dockerfile.use-installer | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dockerfiles/Dockerfile.use-installer b/dockerfiles/Dockerfile.use-installer index c92186b..0f47089 100644 --- a/dockerfiles/Dockerfile.use-installer +++ b/dockerfiles/Dockerfile.use-installer @@ -25,11 +25,12 @@ RUN apt-get update -qq \ # Run regression tests on binaries built from source here # FROM builder as installer -# create an installer from the binaries built from source here +# use COPY --from=builder to get the binaries from builder stage and +# create an installer from those binaries built from source here FROM base as release-candidate -# use --copy-from builder to copy binaries into the right place here if built from source, -# or copy the installer with --copy-from installer +# use COPY --from=builder to copy binaries into the right place here if built from source, +# or copy the installer with COPY --from=installer # or use the pre-built released installer as we do here: RUN wget https://github.com/im-tomu/fomu-toolchain/releases/download/v1.5.6/fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ tar -xvf fomu-toolchain-linux_x86_64-v1.5.6.tar.gz && \ @@ -54,9 +55,13 @@ WORKDIR /home/${USER} FROM release-candidate as fomu-toolchain # Below are some sample commands to build and run a docker images. +# Execute the docker build commands from within the dockerfiles folder. # # docker build -f Dockerfile.use-installer . -t fomu-toolchain # +# Execute the docker run commands from the fomu-workshop folder +# or from your own project's folder as appropriate. +# # docker run -it -v $(pwd):/home/fomu fomu-toolchain bash # # The --privileged param may be used to allow access to usb devices From a745764aac6cc588d6190bfde3a582bb94a2d4c2 Mon Sep 17 00:00:00 2001 From: Thirsty2 Date: Wed, 14 Oct 2020 23:17:38 -0700 Subject: [PATCH 5/5] Added github action to publish docker image --- .github/workflows/docker-publish.yml | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..3314705 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,51 @@ +name: Docker + +on: + push: + branches: + - master + - Dockerfile-use-installer + pull_request: + branches: + - master + - Dockerfile-use-installer + workflow_dispatch: + +env: + IMAGE_NAME: fomu-toolchain + +jobs: + push: + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build ./dockerfiles --file dockerfiles/Dockerfile.use-installer --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$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" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION \ No newline at end of file