From c3b1707bdb9f7a6bc4b14cefcf3f852363f1e298 Mon Sep 17 00:00:00 2001 From: Will Fantom Date: Sun, 15 Oct 2023 18:35:03 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Docker=20Support=20=F0=9F=90=B3=20(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: added dockerfile and relvant docs * feat: added ci to publish docker images * chore: bumped all checkout actions to v4 * chore: removed unnecessary deps from build stage * chore: changed build targets to amd64 and arm64 only * chore: moved docker publish logic to push trigger Switched the docker image build/publish pipeline event to a push event on either a `v*` tag or to the main branch. * fix: README * feat: publish => docker * feat: dont run on main push lets only publish releases instead --------- Co-authored-by: Evangelos Paterakis --- .github/workflows/ci.yml | 2 +- .github/workflows/docker.yml | 45 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 8 ++++--- Dockerfile | 10 ++++++++ README.md | 6 +++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index accd31e..44fc445 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download source - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install Crystal uses: crystal-lang/install-crystal@v1 - name: Install shards diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d39f34d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,45 @@ +name: Docker + +on: + push: + tags: + - 'v*' + +jobs: + publish-docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup 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: Container Metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/blahaj + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + - name: Build and Push Container + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 49c2361..512f40e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,7 @@ name: Release + on: workflow_dispatch + jobs: build_linux_static: runs-on: ubuntu-latest @@ -7,10 +9,10 @@ jobs: image: crystallang/crystal:latest-alpine steps: - name: Download source - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Retrieve version run: | - echo "::set-output name=VERSION::$(shards version)" + echo "VERSION=$(shards version)" >> "$GITHUB_OUTPUT" id: version - name: Build run: make static_mt @@ -26,7 +28,7 @@ jobs: runs-on: ubuntu-latest needs: build_linux_static steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/download-artifact@v2 with: path: ./GH_ARTIFACTS diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7cd4eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM --platform=linux/amd64 crystallang/crystal:latest-alpine as builder + +WORKDIR /root/src +COPY . . +RUN shards build --production --no-debug --release -Dpreview_mt --static + + +FROM scratch +COPY --from=builder /root/src/bin/blahaj /usr/local/bin/blahaj +ENTRYPOINT [ "blahaj" ] diff --git a/README.md b/README.md index 6b4fc7e..ee7d377 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ They are built & published by our lovely [actions](https://github.com/GeopJr/BLA Arch Linux users can install the [blahaj](https://aur.archlinux.org/packages/blahaj) (or the [blahaj-git](https://aur.archlinux.org/packages/blahaj-git)) AUR package. +### Docker + +``` +docker run --rm -it --name blahaj ghcr.io/geopjr/blahaj -h +``` + ### Building #### Dependencies