diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml new file mode 100644 index 0000000..5149372 --- /dev/null +++ b/.github/workflows/dev-build.yml @@ -0,0 +1,81 @@ +name: Development Build + +on: + pull_request: + branches: + - main + types: + - opened + - synchronize + +jobs: + dev-build: + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Extract Version for Dev Build + id: versioning + run: | + branch_name=${{ github.head_ref }} + if [[ "$branch_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + version=${branch_name#v} + echo "version=$version" >> $GITHUB_OUTPUT + echo "ghcr_tag=ghcr.io/thunderatz/stm32cubemx:${version}-dev" >> $GITHUB_OUTPUT + else + echo "Error: Branch name must follow 'vx.y.z' pattern." >&2 + exit 1 + fi + shell: bash + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Dev Docker Image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }} + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }} + cache-to: type=inline + + - name: Build and Push Dev Docker Image for G4 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=G4 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-g4 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-g4 + cache-to: type=inline + + - name: Build and Push Dev Docker Image for F4 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=F4 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-f4 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-f4 + cache-to: type=inline + + - name: Build and Push Dev Docker Image for F1 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=F1 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-f1 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-f1 + cache-to: type=inline diff --git a/.github/workflows/prod-build.yml b/.github/workflows/prod-build.yml new file mode 100644 index 0000000..3c50392 --- /dev/null +++ b/.github/workflows/prod-build.yml @@ -0,0 +1,89 @@ +name: Production Build + +on: + pull_request: + branches: + - main + types: + - closed + +jobs: + prod-build: + if: github.event.pull_request.merged == true + + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Extract Version for Production Build + id: versioning + run: | + branch_name=${{ github.head_ref }} + if [[ "$branch_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + version=${branch_name#v} + echo "version=$version" >> $GITHUB_OUTPUT + echo "ghcr_tag=ghcr.io/thunderatz/stm32cubemx:${version}" >> $GITHUB_OUTPUT + echo "docker_tag=thunderatz/stm32cubemx:${version}" >> $GITHUB_OUTPUT + else + echo "Error: Branch name must follow 'vx.y.z' pattern." >&2 + exit 1 + fi + shell: bash + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and Push Production Docker Image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }},${{ steps.versioning.outputs.docker_tag }} + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }} + cache-to: type=inline + + - name: Build and Push Production Docker Image for G4 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=G4 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-g4,${{ steps.versioning.outputs.docker_tag }}-g4 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-g4 + cache-to: type=inline + + - name: Build and Push Production Docker Image for F4 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=F4 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-f4,${{ steps.versioning.outputs.docker_tag }}-f4 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-f4 + cache-to: type=inline + + - name: Build and Push Production Docker Image for F1 MCU + uses: docker/build-push-action@v3 + with: + context: . + build-args: MCU=F1 + push: true + tags: ${{ steps.versioning.outputs.ghcr_tag }}-f1,${{ steps.versioning.outputs.docker_tag }}-f1 + cache-from: type=registry,ref=ghcr.io/thunderatz/stm32cubemx:${{ steps.versioning.outputs.version }}-f1 + cache-to: type=inline diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8caff8b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM ubuntu:24.04 AS stm32cubemx + +RUN apt-get update -y && \ + apt-get upgrade -y && \ + apt-get install -y \ + unzip \ + xvfb \ + wget \ + openjdk-21-jre \ + libgbm1 \ + && apt-get clean + +RUN mkdir st && cd st && \ + wget -nv https://sw-center.st.com/packs/resource/library/stm32cube_mx_v6130-lin.zip && \ + unzip -q stm32cube_mx_v6130-lin.zip && \ + unzip -q JavaJre.zip && \ + mv MX /root/STM32CubeMX && \ + mv jre /root/STM32CubeMX && \ + cd .. && rm -rf st + +ENV CUBE_PATH="/root/STM32CubeMX" + +RUN echo "exit" > /root/cube-init && \ + Xvfb :10 -ac > /dev/null & \ + export DISPLAY=:10 && \ + $CUBE_PATH/STM32CubeMX -q /root/cube-init && \ + rm /root/cube-init && \ + pkill -f Xvfb + + +RUN rm /tmp/.X10-lock + +ARG MCU + +RUN if [ -z "$MCU" ]; then \ + echo "Docker built without MCU repository."; \ + else \ + apt-get install -y git && \ + mkdir -p /root/STM32Cube/Repository && cd /root/STM32Cube/Repository && \ + git clone https://github.com/STMicroelectronics/STM32Cube${MCU}.git && \ + cd STM32Cube${MCU} && \ + git submodule update --init --recursive; \ + fi diff --git a/README.md b/README.md index 7573630..d68f7dd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,131 @@ -# stm32cubemx_docker -Docker configurations for STM32 development with CubeMX + +
Eduardo Barreto 💻 📖 🔬 👀 |
+ Gabriel Cosme Barbosa 💻 🔬 👀 |
+