Skip to content

Commit a1ab5ae

Browse files
committed
add github workflows to build a container and to publish the gem
1 parent 018ef4c commit a1ab5ae

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.git
2+
/.github
23
/deployment
34
.*.swp

.github/workflows/build.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build the ruby gem in a container
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
build-ruby-gem:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout project code
10+
uses: actions/checkout@v4
11+
12+
- name: Setup Docker builder
13+
uses: docker/setup-buildx-action@v3
14+
15+
- name: Build container for build target
16+
uses: docker/build-push-action@v5
17+
with:
18+
context: .
19+
file: ./deployment/Containerfile
20+
target: build
21+
push: false
22+
load: true
23+
tags: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }}
24+
cache-from: type=gha
25+
cache-to: type=gha,mode=max

.github/workflows/release.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build the ruby gem in a container and publish it on Github Package Repository
2+
on:
3+
release:
4+
types:
5+
- published
6+
7+
jobs:
8+
build-ruby-gem:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout project code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Docker builder
15+
uses: docker/setup-buildx-action@v3
16+
17+
- name: Build container for build target
18+
uses: docker/build-push-action@v5
19+
with:
20+
context: .
21+
file: ./deployment/Containerfile
22+
target: build
23+
push: false
24+
load: true
25+
tags: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }}
26+
cache-from: type=gha
27+
cache-to: type=gha,mode=max
28+
29+
- name: Publish gem to Github Package Repository
30+
uses: addnab/docker-run-action@v3
31+
env:
32+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
33+
OWNER: ${{ github.repository_owner }}
34+
with:
35+
image: linuxfrorg/board-sse-linuxfr.org:${{ github.sha }}
36+
options: >-
37+
-e OWNER
38+
-e GEM_HOST_API_KEY
39+
run: |
40+
set -eux
41+
IFS=$'\n\t'
42+
43+
mkdir -p "${HOME}/.gem"
44+
touch "${HOME}/.gem/credentials"
45+
chmod 0600 "${HOME}/.gem/credentials"
46+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > "${HOME}/.gem/credentials"
47+
gem push --KEY github --host "https://rubygems.pkg.github.com/${OWNER}" *.gem

deployment/Containerfile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:3-slim-bookworm
1+
FROM ruby:3-slim-bookworm AS build
22

33
LABEL org.opencontainers.image.title="LinuxFr.org boards"
44
LABEL org.opencontainers.image.description="Chat rooms for LinuxFr"
@@ -10,20 +10,29 @@ LABEL org.opencontainers.image.authors="Adrien Dorsaz <[email protected]>"
1010

1111
ARG UID=1200
1212

13-
RUN apt-get update \
14-
# Install dependencies \
15-
&& apt-get install -y --no-install-recommends \
16-
build-essential ruby ruby-dev \
17-
&& apt-get clean
13+
RUN <<EOF
14+
set -eux
15+
IFS=$'\n\t'
16+
17+
apt-get update
18+
19+
apt-get install -y --no-install-recommends \
20+
build-essential ruby ruby-dev
21+
22+
apt-get clean
23+
EOF
1824

1925
USER ${UID}
2026
WORKDIR /linuxfr-board
2127
ENV HOME=/linuxfr-board
2228

2329
# Install board-linuxfr
2430
COPY --chown=${UID}:0 --chmod=770 . .
25-
RUN gem build board-linuxfr.gemspec \
26-
&& gem install ./board-linuxfr-*.gem
31+
RUN gem build board-linuxfr.gemspec
32+
33+
FROM build as productioproduction
34+
35+
RUN gem install ./board-linuxfr-*.gem
2736

2837
# Clean development dependencies
2938
USER 0

0 commit comments

Comments
 (0)