Skip to content

Commit 6575605

Browse files
authored
Merge pull request #1 from renuo/add-dockerfile-and-build-actions
Add Dockerfile and build actions
2 parents eaf7c7a + 7c9b0a3 commit 6575605

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

.github/workflows/docker.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Docker
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
push:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
docker-build:
11+
runs-on: ubuntu-24.04
12+
env:
13+
DOCKER_REPO: ghcr.io/${{ github.repository }}
14+
RUBY_VERSION: 3.4.4
15+
NODE_VERSION: 22.16.0
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Build Docker image
19+
run: ./build.sh
20+
- name: Login to the container registry
21+
uses: docker/login-action@v2
22+
with:
23+
registry: ${{ env.DOCKER_REPO }}
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
if: github.event_name == 'push'
27+
- name: Push Docker image
28+
run: ./push.sh
29+
if: github.event_name == 'push'

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This Dockerfile is designed for running the CI of Ruby on Rails projects
2+
ARG RUBY_VERSION=3.4.4
3+
FROM docker.io/library/ruby:$RUBY_VERSION
4+
5+
RUN apt-get update -qq && \
6+
apt-get install --no-install-recommends -y postgresql-client libjemalloc2 && \
7+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
8+
9+
# Install yarn and node
10+
ARG NODE_VERSION=22.14.0
11+
ARG YARN_VERSION=1.22.22
12+
ENV PATH=/usr/local/node/bin:$PATH
13+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
14+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
15+
npm install -g yarn@$YARN_VERSION && \
16+
rm -rf /tmp/node-build-master
17+
18+
ENV RAILS_ENV="test"

build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [ -z "${RUBY_VERSION:-}" ]; then
6+
echo "RUBY_VERSION is not set"
7+
exit 1
8+
fi
9+
10+
if [ -z "${NODE_VERSION:-}" ]; then
11+
echo "NODE_VERSION is not set"
12+
exit 1
13+
fi
14+
15+
docker build --build-arg RUBY_VERSION="$RUBY_VERSION" --build-arg NODE_VERSION="$NODE_VERSION" -t "${DOCKER_REPO}:ruby-${RUBY_VERSION}-node-${NODE_VERSION}" .

push.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [ -z "${RUBY_VERSION:-}" ]; then
6+
echo "RUBY_VERSION is not set"
7+
exit 1
8+
fi
9+
10+
if [ -z "${NODE_VERSION:-}" ]; then
11+
echo "NODE_VERSION is not set"
12+
exit 1
13+
fi
14+
15+
docker push "${DOCKER_REPO}:ruby-${RUBY_VERSION}-node-${NODE_VERSION}"

0 commit comments

Comments
 (0)