From e8e157bd63ff91dd07e3f151d0a6cfc6b63abdb7 Mon Sep 17 00:00:00 2001 From: kentalee <24422888+kentalee@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:20:07 +0800 Subject: [PATCH] update --- .github/workflows/docker-image.yml | 31 ++++++++++++------- Dockerfile | 48 ++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 0156ed9..266089a 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,16 +1,16 @@ name: Build and Push Docker Image on: - push: - branches: - - main # Change to your desired branch - pull_request: - branches: - - main # Change to your desired branch + workflow_dispatch: + inputs: + branch: + description: 'Target branch' + required: false + default: 'main' jobs: build: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Checkout repository @@ -24,13 +24,24 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push Docker image + + - name: Declare some variables + shell: bash + run: | + sha_short=$(git rev-parse --short $GITHUB_SHA) + commit_date=$(git log -1 --format=%cd --date=format:%Y%m%d) + echo "REPO_TAG=${commit_date}-${sha_short}" >> "$GITHUB_ENV" + + - name: Build and push image uses: docker/build-push-action@v4 with: context: . + pull: true push: true - tags: ${{ secrets.DOCKER_USERNAME }}/picolab:latest + file: Dockerfile + tags: ${{ secrets.DOCKER_USERNAME }}/${{ vars.DOCKER_REPO }}:${{ env.REPO_TAG }} + build-args: | + APT_MIRROR=${{ vars.APT_MIRROR }} - name: Log out from Docker Hub run: docker logout diff --git a/Dockerfile b/Dockerfile index 2029950..ef5a9da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,39 @@ -FROM ubuntu:nobel -RUN apt-get update && apt-get dist-upgrade -y && \ - apt-get install -y build-essential wget curl git python3 net-tools nano cmake \ - gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \ - automake autoconf texinfo libtool libftdi-dev libusb-1.0-0-d +FROM ubuntu:latest -RUN mkdir /opt/pico-sdk && cd /opt/pico-sdk && \ - git clone https://github.com/raspberrypi/pico-sdk . && git submodule update --init --recursive +ARG APT_MIRROR=ports.ubuntu.com -RUN mkdir /opt/openocd && cd /opt/openocd && \ - git clone https://github.com/raspberrypi/openocd --branch rp2040 . && git submodule update --init --recursive && \ - ./bootstrap && ./configure --enable-cmsis-dap && make -j4 && make install +ENV DEBIAN_FRONTEND=noninteractive -RUN mkdir /opt/pico-lab && cd /opt/pico-lab && \ - git clone https://github.com/wuxx/pico-lab . && source ./tools/env.sh +RUN cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.backup ;\ + sed -i "s@/ports.ubuntu.com/@/${APT_MIRROR}/@g" /etc/apt/sources.list.d/ubuntu.sources ;\ + apt-get update && apt install ca-certificates -y ;\ + sed -i 's@http://@https://@g' /etc/apt/sources.list.d/ubuntu.sources ;\ + apt-get update && apt-get dist-upgrade -y ;\ + apt-get install --no-install-recommends -y curl git net-tools wget nano unzip \ + pkg-config cmake build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \ + automake autoconf texinfo libtool libftdi-dev libusb-1.0-0-dev libhidapi-dev ;\ + mv -f /etc/apt/sources.list.d/ubuntu.sources.backup /etc/apt/sources.list.d/ubuntu.sources ;\ + apt clean && apt autoclean; + +RUN mkdir /opt/pico-sdk && cd /opt/pico-sdk ;\ + git clone https://github.com/raspberrypi/pico-sdk --single-branch . ;\ + git submodule update --init --remote --checkout --single-branch ;\ + \ + mkdir /opt/openocd && cd /opt/openocd ;\ + git clone https://github.com/raspberrypi/openocd --single-branch --branch rp2040 . ;\ + git submodule set-url tools/git2cl "https://git.savannah.nongnu.org/git/git2cl.git" ;\ + git submodule update --init --remote --checkout --single-branch ;\ + ./bootstrap && ./configure --enable-cmsis-dap && make -j4 && make install ;\ + rm -rf /opt/openocd ;\ + mkdir -p /opt/openocd/src ;\ + ln -s $(which openocd) /opt/openocd/src/ ;\ + ln -s /usr/local/share/openocd/scripts /opt/openocd/tcl ;\ + echo "adapter speed 5000" >> /opt/openocd/tcl/target/rp2040.cfg ;\ + echo "export OPENOCD_ROOT=/opt/openocd" >> /etc/profile.d/02-openocd.sh ;\ + \ + mkdir /opt/pico-lab && cd /opt/pico-lab ;\ + git clone https://github.com/wuxx/pico-lab --single-branch . ;\ + git submodule update --init --remote --checkout --single-branch ;\ + echo "export export PATH=\${PATH}:\${pico-lab}/tools" >> /etc/profile.d/03-pico-lab.sh ;\ + \ + find /opt -name ".git" -type d -exec rm -rf {} + ; \ No newline at end of file