Skip to content

Commit

Permalink
fixup! [actions] upload docker image tar to artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnotran committed Jun 20, 2024
1 parent 307002f commit 4e9ff7f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: arm-gcc-${{ matrix.gcc_ver }}
runs-on: ubuntu-22.04
container:
image: siliconlabsinc/ot-efr32-dev:latest
image: siliconlabsinc/ot-efr32-dev:${{ github.sha }}
options: --user 1001
strategy:
fail-fast: false
Expand Down
93 changes: 58 additions & 35 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
name: Docker

env:
TEST_TAG: siliconlabsinc/ot-efr32-dev:test
BASE_IMAGE: siliconlabsinc/ot-efr32-dev:base
SHA_TAG: siliconlabsinc/ot-efr32-dev:${{ github.sha }}
LATEST_TAG: siliconlabsinc/ot-efr32-dev:latest
DOCKER_IMAGE_ARTIFACT_NAME: ot-efr32-dev-image-${{ github.sha }}-${{ github.event_name}}
DOCKER_IMAGE_TAR: ot-efr32-dev-image-${{ github.sha }}.tar
DOCKER_IMAGE_ARTIFACT_NAME: ot-efr32-dev-image-${{ github.sha }}-${{ github.event_name}}.tar

on:
push:
Expand All @@ -54,6 +53,11 @@ jobs:
build:
name: Build Docker Image
runs-on: ubuntu-22.04
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
Expand All @@ -66,32 +70,55 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
with:
driver-opts: network=host

- name: Build and export to Docker context
- name: Build and export to Docker context (Base image)
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
# load: true
build-args: |
- BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
platforms:
linux/amd64
file: docker/base.Dockerfile
load: true
platforms: linux/amd64
push: true
tags: |
${{ env.TEST_TAG }}
${{ env.SHA_TAG }}
localhost:5000/${{ env.BASE_IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=oci,dest=${{ env.DOCKER_IMAGE_TAR}}

# - name: Container image sanity checks
# run: |
# # Download container-structure-test
# curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 \
# && chmod +x container-structure-test-linux-amd64
- name: Build and export to Docker context (ot-efr32-dev)
uses: docker/build-push-action@v5
with:
context: .
file: docker/ot-efr32-dev.Dockerfile
platforms: linux/amd64
push: true
tags: |
localhost:5000/${{ env.SHA_TAG }}
no-cache: true

- name: Inspect Docker image
run: docker inspect ${{ env.SHA_TAG }}

- name: Container image sanity checks
run: |
# Download container-structure-test
curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 \
&& chmod +x container-structure-test-linux-amd64
# # Run tests
# ./container-structure-test-linux-amd64 test --config docker/test-ot-efr32-dev.yml --image ${{ env.TEST_TAG }}
# Run tests
./container-structure-test-linux-amd64 test --config docker/test-ot-efr32-dev.yml --image localhost:5000/${{ env.SHA_TAG }}
- name: Export Docker image to tarball
uses: docker/build-push-action@v5
with:
context: .
file: docker/ot-efr32-dev.Dockerfile
platforms:
linux/amd64
tags: |
${{ env.SHA_TAG }}
outputs: type=docker,dest=/tmp/${{ env.DOCKER_IMAGE_ARTIFACT_NAME}}

# - name: Create LFS file hash list
# run: git -C third_party/silabs/gecko_sdk lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
Expand All @@ -108,13 +135,13 @@ jobs:

# - name: Test build inside container
# run: |
# docker run -v ${{ github.workspace }}:/ot-efr32/ --user $(id -u) --rm ${{ env.TEST_TAG }} script/build --skip-silabs-apps brd4151a
# docker run -v ${{ github.workspace }}:/ot-efr32/ --user $(id -u) --rm ${{ env.SHA_TAG }} script/build --skip-silabs-apps brd4151a

- name: Upload docker image
uses: actions/upload-artifact@v4.3.3
with:
name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}
path: ${{ env.DOCKER_IMAGE_TAR }}
path: /tmp/${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}

publish:
name: Publish to DockerHub
Expand All @@ -131,36 +158,32 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Docker image
id: download
uses: actions/download-artifact@v4.1.7
with:
name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}

- name: Show downloaded Docker image
run: ls -ahl ${{ github.workspace }}
path: /tmp

- name: Load Docker image
run: docker load -i ${{ github.workspace }}/${{ env.DOCKER_IMAGE_TAR }}
run: |
docker load --input ${{ steps.download.outputs.download-path }}/${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}
docker image ls -a
- name: Build and push
uses: docker/build-push-action@v5
if: github.ref == 'refs/heads/main'
with:
context: .
file: docker/Dockerfile
file: docker/ot-efr32-dev.Dockerfile
push: true
tags: |
${{ env.SHA_TAG }}
tags: ${{ env.SHA_TAG }}
platforms:
linux/amd64

- name: Tag `latest` and push
uses: docker/build-push-action@v5
if: github.ref == 'refs/heads/main'
with:
context: .
file: docker/Dockerfile
file: docker/ot-efr32-dev.Dockerfile
push: true
tags: |
${{ env.LATEST_TAG }}
tags: ${{ env.LATEST_TAG }}
platforms:
linux/amd64
20 changes: 2 additions & 18 deletions docker/Dockerfile → docker/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ubuntu:22.04
ARG BASE_IMAGE='ubuntu:22.04'
FROM ${BASE_IMAGE} as base

ENV TZ="America/New_York"
ENV repo_dir="/ot-efr32"
Expand All @@ -22,20 +23,3 @@ RUN ./script/bootstrap arm_toolchain
# Install Python packages
COPY ./requirements.txt .
RUN ./script/bootstrap python

# Label the build date before downloading slc to force slc to always be downloaded during a docker build
ARG BUILD_DATE
LABEL build_date=${BUILD_DATE}

COPY ./script/bootstrap_silabs \
./script/
ENV SLC_INSTALL_DIR=/opt/slc_cli
RUN mkdir ${SLC_INSTALL_DIR} && \
./script/bootstrap silabs


# Clone repo for convenience
ARG REPO_URL="https://github.com/openthread/ot-efr32"
WORKDIR /
RUN rm -rf ${repo_dir} && git clone ${REPO_URL} ${repo_dir}
WORKDIR ${repo_dir}
21 changes: 21 additions & 0 deletions docker/ot-efr32-dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG BASE_IMAGE='siliconlabsinc/ot-efr32-dev:base'

FROM ${BASE_IMAGE} AS ot-efr32-dev

COPY ./script/bootstrap_silabs \
./script/
ENV SLC_INSTALL_DIR=/opt/slc_cli
RUN mkdir ${SLC_INSTALL_DIR} && \
./script/bootstrap silabs


# Change workdir to root temporarily
WORKDIR /

# Clone repo for convenience
ARG REPO_URL="https://github.com/openthread/ot-efr32"
ENV repo_dir="/ot-efr32"
RUN rm -rf ${repo_dir} && git clone ${REPO_URL} ${repo_dir}

# Change workdir back to repo
WORKDIR ${repo_dir}

0 comments on commit 4e9ff7f

Please sign in to comment.