From bb316dcf1002434d822a590119a5be8069a78b40 Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 14 May 2025 16:15:55 -0300 Subject: [PATCH 1/3] Adding docker image generation --- Dockerfile | 15 +++++++++++++++ README.md | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2786a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM gcc:latest AS builder + +WORKDIR /usr/src/app + +COPY . . + +RUN make + +FROM debian:bookworm AS runtime + +WORKDIR /usr/src/app + +COPY --from=builder /usr/src/app/sort . +ENV TERM=xterm +CMD ["./sort"] diff --git a/README.md b/README.md index cad3d0d..746164b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ![Contributions](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=information&style=for-the-badge) +![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white) ![Ubuntu](https://img.shields.io/badge/Ubuntu-E95420?style=for-the-badge&logo=ubuntu&logoColor=white) ![MAC](https://img.shields.io/badge/MAC-000000?style=for-the-badge&logo=macos&logoColor=white) ![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white) @@ -44,7 +45,19 @@ Save results in a text file | NO Display arrays | YES Display execution time | YES -Note: you need to have the [GCC compiler](https://gcc.gnu.org/) installed in your machine to execute the instructions below to run the program. +Note: you need to have the [GCC compiler](https://gcc.gnu.org/) or docker environment installed in your machine to execute the instructions below to run the program. +___ +#### Docker +- Build the image: +```shell +docker build -t sort_algorithms . +``` +- Execute the image: +```shell +docker run -it --rm \ + -v /data.txt:/usr/src/app/data.txt \ + sort_algorithms +``` ___ #### Linux & MAC Open a terminal and go to project's directory. Execute ```make``` in terminal allow to compile the program. Commands avaliable to execute with make (```make ${command}```): From 149cafb959b3de6be68ca475156ec83070540caf Mon Sep 17 00:00:00 2001 From: Henrique Date: Mon, 19 May 2025 13:58:22 -0300 Subject: [PATCH 2/3] Creating Package for repository --- .github/build.yml | 21 +++++++++++++++++++++ .github/publish.yml | 36 ++++++++++++++++++++++++++++++++++++ README.md | 11 +++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .github/build.yml create mode 100644 .github/publish.yml diff --git a/.github/build.yml b/.github/build.yml new file mode 100644 index 0000000..bb9ee03 --- /dev/null +++ b/.github/build.yml @@ -0,0 +1,21 @@ +name: Build CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [gcc, clang] + + steps: + - uses: actions/checkout@v4 + - name: Install compiler + run: sudo apt-get update && sudo apt-get install -y ${{ matrix.compiler }} + - name: Build + run: make CC=${{ matrix.compiler }} diff --git a/.github/publish.yml b/.github/publish.yml new file mode 100644 index 0000000..76acdae --- /dev/null +++ b/.github/publish.yml @@ -0,0 +1,36 @@ +name: Build and Push Multiarch Docker image to GHCR + +on: + push: + branches: + - master + +jobs: + build-and-push: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in 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 (multiarch) + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ghcr.io/${{ github.repository }}:latest + platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/README.md b/README.md index 746164b..b276fa7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,17 @@ Display execution time | YES Note: you need to have the [GCC compiler](https://gcc.gnu.org/) or docker environment installed in your machine to execute the instructions below to run the program. ___ +#### Generated Image From Packages +- Pull the image: +```shell +docker pull ghcr.io/h-ssiqueira/sort_algorithms:latest +``` +- Run the image into a container: +```shell +docker run -it --rm \ + -v /data.txt:/usr/src/app/data.txt \ + ghcr.io/h-ssiqueira/sort_algorithms:latest +``` #### Docker - Build the image: ```shell From 47ef9b459f7629d18d9b6f8a90907ee51d2d81d0 Mon Sep 17 00:00:00 2001 From: Henrique Date: Mon, 19 May 2025 14:02:11 -0300 Subject: [PATCH 3/3] Adjusting workflows --- .github/{ => workflows}/build.yml | 0 .github/{ => workflows}/publish.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/build.yml (100%) rename .github/{ => workflows}/publish.yml (100%) diff --git a/.github/build.yml b/.github/workflows/build.yml similarity index 100% rename from .github/build.yml rename to .github/workflows/build.yml diff --git a/.github/publish.yml b/.github/workflows/publish.yml similarity index 100% rename from .github/publish.yml rename to .github/workflows/publish.yml