diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bb9ee03 --- /dev/null +++ b/.github/workflows/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/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..76acdae --- /dev/null +++ b/.github/workflows/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/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..b276fa7 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,30 @@ 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. +___ +#### 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 +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}```):