Skip to content

Commit 693f825

Browse files
authored
Merge pull request #2 from xavius-rb/build/001
Build/001
2 parents e706480 + ab857c9 commit 693f825

File tree

70 files changed

+1601
-736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1601
-736
lines changed

.github/workflows/docker-image.yml

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Image CI
1+
name: Docker CI
22

33
on:
44
push:
@@ -21,38 +21,37 @@ jobs:
2121
- name: Cache Docker layers
2222
uses: actions/cache@v4
2323
with:
24-
path: /tmp/.buildx-cache
25-
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
24+
path: ${{ runner.temp }}/.buildx-cache # Use GitHub Actions cache directory
25+
key: ${{ runner.os }}-buildx-${{ github.sha }}
2626
restore-keys: |
27-
${{ runner.os }}-multi-buildx
27+
${{ runner.os }}-buildx-
2828
2929
- name: Build image
3030
uses: docker/build-push-action@v5
3131
with:
32-
cache-from: type=local,src=/tmp/.buildx-cache
33-
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
32+
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
33+
cache-to: type=local,mode=max,dest=${{ runner.temp }}/.buildx-cache-new
3434
context: .
3535
target: build
3636
tags: ${{ env.TEST_IMAGE_TAG }}
37-
outputs: type=docker,dest=/tmp/${{ env.TEMP_IMAGE_NAME }}.tar
37+
outputs: type=docker,dest=${{ runner.temp }}/${{ env.TEMP_IMAGE_NAME }}.tar
3838

3939
- name: Move cache
4040
run: |
41-
rm -rf /tmp/.buildx-cache
42-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
41+
rm -rf ${{ runner.temp }}/.buildx-cache
42+
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
4343
4444
- name: Load built image
45-
run: docker load -i /tmp/${{ env.TEMP_IMAGE_NAME }}.tar
45+
run: docker load -i ${{ runner.temp }}/${{ env.TEMP_IMAGE_NAME }}.tar
4646

47-
- name: DB Test Prepare
47+
- name: Run Tests
4848
run: |
4949
docker compose up -d database
5050
docker compose run --rm -e RAILS_ENV=test web bin/rails db:test:prepare
51+
docker compose run --rm -e RAILS_ENV=test web bin/rails spec
5152
52-
- name: Run Tests
53-
run: docker compose run --rm -e RAILS_ENV=test web bin/rails spec
54-
55-
- name: Login to DockerHub
53+
- name: Login to DockerHub (if main branch)
54+
if: github.ref == 'refs/heads/main'
5655
uses: docker/login-action@v3
5756
with:
5857
username: ${{ secrets.DOCKERHUB_USERNAME }}
@@ -62,11 +61,11 @@ jobs:
6261
if: github.ref == 'refs/heads/main'
6362
uses: docker/build-push-action@v5
6463
with:
64+
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
6565
context: .
6666
push: true
6767
target: deployment
6868
tags: xavius/wave-connect:${{ github.sha }}, xavius/wave-connect:latest
69-
#repository: your-docker-hub-username/your-repository-name
7069

7170
deploy:
7271
needs: build-and-test

Dockerfile

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ WORKDIR /rails
99

1010
# Install dependencies for both build and runtime
1111
RUN apk add --no-cache \
12-
libpq \
12+
build-base \
13+
libpq-dev \
1314
libxml2 \
1415
tzdata \
15-
bash \
1616
gcompat
1717

18+
# Set environment variables
19+
ENV BUNDLE_PATH="/usr/local/bundle"
20+
ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=true
21+
1822
# Throw-away build stage to reduce size of final image
1923
FROM base as build
2024

2125
# Install build dependencies and Node.js
2226
RUN apk add --no-cache --virtual .build-deps \
23-
build-base \
2427
git \
2528
libpq-dev \
2629
libxml2-dev && \
@@ -29,12 +32,9 @@ RUN apk add --no-cache --virtual .build-deps \
2932

3033
# Copy Gemfile and Gemfile.lock before other files (leverage Docker cache)
3134
COPY Gemfile Gemfile.lock ./
32-
33-
# Install application gems
34-
RUN bundle install --jobs "$(nproc)" && \
35-
rm -rf /usr/local/bundle/cache && \
36-
find /usr/local/bundle/gems/ -name "*.c" -delete && \
37-
find /usr/local/bundle/gems/ -name "*.o" -delete
35+
RUN bundle install --jobs 2 --path="${BUNDLE_PATH}" && \
36+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
37+
bundle exec bootsnap precompile --gemfile
3838

3939
# Copy application code
4040
COPY . .
@@ -46,10 +46,10 @@ RUN bundle exec bootsnap precompile app/ lib/
4646
RUN apk del .build-deps
4747

4848
# Final stage for app image
49-
FROM base as deployment
49+
FROM base
5050

5151
# Copy built artifacts: gems and application code
52-
COPY --from=build /usr/local/bundle /usr/local/bundle
52+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
5353
COPY --from=build /rails /rails
5454

5555
# Ensure permissions are correct for non-root user

Gemfile

+23-30
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
ruby "3.3.4"
3+
ruby '3.3.5'
44

55
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
6-
gem "rails", "~> 7.1.3", ">= 7.1.3.3"
7-
8-
gem "bootsnap", require: false
9-
gem "cssbundling-rails"
10-
gem "faraday"
11-
gem "jbuilder"
12-
gem "jsbundling-rails"
13-
gem "pg"
14-
gem "puma"
15-
gem "redis"
16-
gem "sprockets-rails"
17-
gem "stimulus-rails"
18-
gem "turbo-rails"
6+
gem 'rails', '~> 7.2.0'
7+
8+
gem 'bootsnap', require: false
9+
gem 'cssbundling-rails'
10+
gem 'faraday'
11+
gem 'jbuilder'
12+
gem 'jsbundling-rails'
13+
gem 'pg'
14+
gem 'puma'
15+
gem 'redis'
16+
gem 'sprockets-rails'
17+
gem 'stimulus-rails'
18+
gem 'turbo-rails'
1919

2020
group :development, :test do
21-
gem "debug", platforms: %i[ mri windows ]
22-
gem "rspec-rails"
23-
gem "factory_bot_rails"
24-
gem "faker"
25-
end
26-
27-
group :development do
28-
gem "web-console"
29-
30-
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
31-
# gem "rack-mini-profiler"
32-
33-
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
34-
# gem "spring"
21+
gem 'brakeman', require: false
22+
gem 'debug', platforms: %i[mri windows], require: 'debug/prelude'
23+
gem 'rubocop-rails-omakase', require: false
24+
25+
# ADDED DEVELOPMENT GEMS
26+
gem 'factory_bot_rails'
27+
gem 'faker'
28+
gem 'rspec-rails'
3529
end
36-

0 commit comments

Comments
 (0)