diff --git a/.dockerignore b/.dockerignore index 58b45bf..6f3eb16 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ /.git +/.github /deployment .*.swp diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml new file mode 100644 index 0000000..6b1e053 --- /dev/null +++ b/.github/workflows/build-and-publish.yaml @@ -0,0 +1,65 @@ +name: Build the ruby gem in a container and publish it on Github Package Repository +on: + pull_request: + release: + types: + - publish + +jobs: + build-ruby-gem: + runs-on: ubuntu-latest + steps: + - name: Checkout project code + uses: actions/checkout@v4 + + - name: Setup Docker builder + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build container for build target + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployment/Containerfile + target: build + push: false + load: true + tags: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Publish gem to Github Package Repository + uses: addnab/docker-run-action@v3 + env: + GITHUB_EVENT_NAME: ${{ github.event_name }} + GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" + OWNER: ${{ github.repository_owner }} + with: + image: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }} + options: >- + -e OWNER + -e GEM_HOST_API_KEY + -e GITHUB_EVENT_NAME + run: | + set -eux + IFS=$'\n\t' + + if [ "${GITHUB_EVENT_NAME}" = 'release' ] + then + echo "Start publish a new release" + else + echo "Skip publish step, because we are not publishing a release" + exit 0 + fi + + mkdir -p "${HOME}/.gem" + touch "${HOME}/.gem/credentials" + chmod 0600 "${HOME}/.gem/credentials" + printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > "${HOME}/.gem/credentials" + gem push --KEY github --host "https://rubygems.pkg.github.com/${OWNER}" *.gem diff --git a/deployment/Containerfile b/deployment/Containerfile index 2a5eb04..58720da 100644 --- a/deployment/Containerfile +++ b/deployment/Containerfile @@ -1,4 +1,4 @@ -FROM ruby:3-slim-bookworm +FROM ruby:3-slim-bookworm AS build LABEL org.opencontainers.image.title="LinuxFr.org boards" LABEL org.opencontainers.image.description="Chat rooms for LinuxFr" @@ -10,11 +10,17 @@ LABEL org.opencontainers.image.authors="Adrien Dorsaz " ARG UID=1200 -RUN apt-get update \ - # Install dependencies \ - && apt-get install -y --no-install-recommends \ - build-essential ruby ruby-dev \ - && apt-get clean +RUN <