From 3c6d0dc0f4cba19850884dd74742241b6259cb6c Mon Sep 17 00:00:00 2001 From: Martin Bruzina Date: Sat, 6 Dec 2025 15:44:22 +0100 Subject: [PATCH 1/3] build: add dockerfile --- Dockerfile | 21 +++++++++++++++++++++ README.md | 10 +++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5cc017c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM ubuntu:22.04 AS builder + +RUN apt update && apt install -y build-essential cmake + +WORKDIR /app + +COPY CMakeLists.txt ./ +COPY src ./src +COPY tests ./tests + +RUN mkdir build && cd build && \ + cmake .. && \ + make + +FROM ubuntu:22.04 + +WORKDIR /app + +COPY --from=builder /app/build/cpp-cli /usr/local/bin/cpp-cli + +ENTRYPOINT ["cpp-cli"] diff --git a/README.md b/README.md index fc20a04..8177bd7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Hello world C++ CLI application. ## Features -- [CI](.github/workflows/ci.yaml) +- [CI](.github/workflows/ci.yaml) on PR or merge to the `main` branch - [Semantic Release](.github/workflows/semantic-release.yaml) on merge to the `main` branch ## Development and Testing @@ -44,3 +44,11 @@ Cleanup: popd rm -rf build/ ``` + +## Distribution + +Docker build and run: + +```shell +sudo docker run --rm $(sudo docker build -q .) +``` From 81bdf2eb78ac732cebba4f3074ed28b168a28800 Mon Sep 17 00:00:00 2001 From: Martin Bruzina Date: Sat, 6 Dec 2025 16:43:10 +0100 Subject: [PATCH 2/3] ci: add docker build and push to ghcr --- .github/workflows/release.yaml | 82 +++++++++++++++++++++++++ .github/workflows/semantic-release.yaml | 45 -------------- .releaserc.yaml | 2 + README.md | 2 +- 4 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/semantic-release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..43f2324 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,82 @@ +--- +name: Semantic Release + +on: + push: + branches: + - main + +jobs: + semantic-release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + outputs: + next-version: ${{ steps.semantic-release.next-version }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install Semantic Release + run: > + npm install + semantic-release + conventional-changelog-conventionalcommits + @semantic-release/changelog + @semantic-release/exec + @semantic-release/git + semantic-release-major-tag + + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + + - name: Run Semantic Release + id: semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npx semantic-release + + docker: + runs-on: ubuntu-latest + needs: semantic-release + if: ${{ needs.semantic-release.outputs.next-version }} + permissions: + packages: write # required to push to GHCR + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker image + run: | + IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/cpp-cli" + V_TAG="${IMAGE_NAME}:v${{ needs.semantic-release.outputs.next-version }}" + LATEST_TAG="${IMAGE_NAME}:latest" + + echo "Building image $V_TAG and $LATEST_TAG" + docker build -t "$V_TAG" -t "$LATEST_TAG" . + + - name: Push Docker image + run: | + IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/cpp-cli" + docker push "${IMAGE_NAME}:v${{ needs.semantic-release.outputs.next-version }}" + docker push "${IMAGE_NAME}:latest" diff --git a/.github/workflows/semantic-release.yaml b/.github/workflows/semantic-release.yaml deleted file mode 100644 index 7367597..0000000 --- a/.github/workflows/semantic-release.yaml +++ /dev/null @@ -1,45 +0,0 @@ ---- -name: Semantic Release - -on: - push: - branches: - - main - -jobs: - release: - name: Release - runs-on: ubuntu-latest - permissions: - contents: write # to be able to publish a GitHub release - issues: write # to be able to comment on released issues - pull-requests: write # to be able to comment on released pull requests - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "lts/*" - - - name: Install Semantic Release - run: > - npm install - semantic-release - conventional-changelog-conventionalcommits - @semantic-release/changelog - @semantic-release/exec - @semantic-release/git - semantic-release-major-tag - - - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies - run: npm audit signatures - - - name: Run Semantic Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npx semantic-release diff --git a/.releaserc.yaml b/.releaserc.yaml index 92b4503..ef0a373 100644 --- a/.releaserc.yaml +++ b/.releaserc.yaml @@ -13,3 +13,5 @@ plugins: - assets: - CHANGELOG.md - semantic-release-major-tag + - - "@semantic-release/exec" + - prepareCmd: "echo \"next-version=${nextRelease.version}\" >> \"$GITHUB_OUTPUT\"" diff --git a/README.md b/README.md index 8177bd7..a274f23 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Hello world C++ CLI application. ## Features - [CI](.github/workflows/ci.yaml) on PR or merge to the `main` branch -- [Semantic Release](.github/workflows/semantic-release.yaml) on merge to the `main` branch +- [Release](.github/workflows/release.yaml) on merge to the `main` branch ## Development and Testing From e819ba0fec4e189e05be69858f1ba6ea61b0cd12 Mon Sep 17 00:00:00 2001 From: Martin Bruzina Date: Sun, 7 Dec 2025 19:17:24 +0100 Subject: [PATCH 3/3] ci: fix version pass between release jobs --- .github/workflows/release.yaml | 8 ++++++-- .releaserc.yaml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 43f2324..dd06008 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,7 +15,7 @@ jobs: issues: write # to be able to comment on released issues pull-requests: write # to be able to comment on released pull requests outputs: - next-version: ${{ steps.semantic-release.next-version }} + next-version: ${{ steps.semantic-release.outputs.next-version }} steps: - name: Checkout repository @@ -45,7 +45,11 @@ jobs: id: semantic-release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npx semantic-release + run: | + npx semantic-release + VERSION=$(cat VERSION) + echo "Next version: $VERSION" + echo "next-version=$VERSION" >> $GITHUB_OUTPUT docker: runs-on: ubuntu-latest diff --git a/.releaserc.yaml b/.releaserc.yaml index ef0a373..10ec844 100644 --- a/.releaserc.yaml +++ b/.releaserc.yaml @@ -14,4 +14,4 @@ plugins: - CHANGELOG.md - semantic-release-major-tag - - "@semantic-release/exec" - - prepareCmd: "echo \"next-version=${nextRelease.version}\" >> \"$GITHUB_OUTPUT\"" + - prepareCmd: "echo ${nextRelease.version} > VERSION"