diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000000..190a5b00e8f1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,31 @@ +name: Build and Push Docker Image + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + run: | + TOOLCHAIN_ID=$(../print_toolchain_checksum.sh) + docker build -t ghcr.io/${{ github.repository }}-toolchain:${{ github.ref_name }} --build-arg VERSION=$TOOLCHAIN_ID . + docker push ghcr.io/${{ github.repository }}-toolchain:${{ github.ref_name }} + working-directory: scripts/docker diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile new file mode 100644 index 000000000000..96c7b0adf639 --- /dev/null +++ b/scripts/docker/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:22.04 as nrfutil-builder + +ARG VERSION +RUN apt-get update && apt-get install -y \ + wget \ + && rm -rf /var/lib/apt/lists/* +RUN wget https://developer.nordicsemi.com/.pc-tools/nrfutil/x64-linux/nrfutil && chmod +x nrfutil \ + && ./nrfutil install toolchain-manager && ./nrfutil toolchain-manager install --toolchain-bundle-id $VERSION +RUN ./nrfutil toolchain-manager env --as-script > /root/toolchain-env.sh + + +FROM ubuntu:22.04 + +# Link to repo (https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#labelling-container-images) +LABEL org.opencontainers.image.source=https://github.com/nrfconnect/sdk-nrf +# Set metadata for an image +LABEL org.opencontainers.image.description="This image contains toolchain for sdk-nrf." + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Copy toolchain +COPY --from=nrfutil-builder /root/ncs/toolchains /root/ncs/toolchains +COPY --from=nrfutil-builder /root/toolchain-env.sh /root/toolchain-env.sh + +# Add entrypoint which calls toolchain-env.sh +ADD entrypoint.sh /root/entrypoint.sh +ENTRYPOINT ["/root/entrypoint.sh"] +CMD ["bin/bash"] diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh new file mode 100755 index 000000000000..e16db5916a10 --- /dev/null +++ b/scripts/docker/entrypoint.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +source /root/toolchain-env.sh +exec "$@"