refactor: consolidate Docker build process
- Removed unused Dockerfile.base and Dockerfile.build. - Combined build steps into the main Dockerfile for improved clarity and maintenance. - Updated base image references accordingly. This change streamlines the Docker build process by reducing the number of Dockerfiles and improving the clarity of dependency management.
This commit is contained in:
parent
2c72e96977
commit
d69a193e6d
39
.github/workflows/docker-main.yml
vendored
39
.github/workflows/docker-main.yml
vendored
@ -13,45 +13,6 @@ env:
|
|||||||
IMAGE_NAME: ${{ github.event.repository.name }}
|
IMAGE_NAME: ${{ github.event.repository.name }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-base-docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v') # 只在发布新版本时构建基础镜像
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Login to ${{ env.REGISTRY }}
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
- name: Build and push base image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: Dockerfile.base
|
|
||||||
push: true
|
|
||||||
tags: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }}:base_main
|
|
||||||
|
|
||||||
build-devel-docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v') # 只在发布新版本时构建基础镜像
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Login to ${{ env.REGISTRY }}
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
- name: Build and push base image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: Dockerfile.base
|
|
||||||
push: true
|
|
||||||
tags: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }}:devel_main
|
|
||||||
|
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
24
Dockerfile
24
Dockerfile
@ -8,15 +8,16 @@
|
|||||||
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
|
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
|
||||||
|
|
||||||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
||||||
# ARG RUBY_VERSION=3.3.5
|
ARG RUBY_VERSION=3.3.5
|
||||||
# FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
||||||
FROM docker.io/songtianlun/today_ai_weather:base_main AS base
|
|
||||||
|
|
||||||
# Rails app lives here
|
# Rails app lives here
|
||||||
WORKDIR /rails
|
WORKDIR /rails
|
||||||
|
|
||||||
# Install base packages
|
# Install base packages
|
||||||
# Move to Base Dockerfile.
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools && \
|
||||||
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||||
|
|
||||||
# Set production environment
|
# Set production environment
|
||||||
ENV RAILS_ENV="production" \
|
ENV RAILS_ENV="production" \
|
||||||
@ -25,12 +26,21 @@ ENV RAILS_ENV="production" \
|
|||||||
BUNDLE_WITHOUT="development"
|
BUNDLE_WITHOUT="development"
|
||||||
|
|
||||||
# Throw-away build stage to reduce size of final image
|
# Throw-away build stage to reduce size of final image
|
||||||
# FROM base AS build
|
FROM base AS build
|
||||||
FROM docker.io/songtianlun/today_ai_weather:devel_main AS build
|
|
||||||
|
|
||||||
# Install packages needed to build gems and node modules
|
# Install packages needed to build gems and node modules
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install --no-install-recommends -y build-essential git node-gyp pkg-config python-is-python3 libpq-dev && \
|
||||||
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||||
|
|
||||||
# Install JavaScript dependencies
|
# Install JavaScript dependencies
|
||||||
# Move to Devel Dockerfile.
|
ARG NODE_VERSION=20.17.0
|
||||||
|
ARG YARN_VERSION=1.22.22
|
||||||
|
ENV PATH=/usr/local/node/bin:$PATH
|
||||||
|
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
|
||||||
|
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
|
||||||
|
npm install -g yarn@$YARN_VERSION && \
|
||||||
|
rm -rf /tmp/node-build-master
|
||||||
|
|
||||||
# Install application gems
|
# Install application gems
|
||||||
COPY Gemfile Gemfile.lock ./
|
COPY Gemfile Gemfile.lock ./
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
ARG RUBY_VERSION=3.3.5
|
|
||||||
# Dockerfile.base
|
|
||||||
FROM docker.io/library/ruby:$RUBY_VERSION-slim
|
|
||||||
|
|
||||||
# Install base packages
|
|
||||||
RUN apt-get update -qq && \
|
|
||||||
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools && \
|
|
||||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
@ -1,30 +0,0 @@
|
|||||||
ARG BASE_IMAGE=docker.io/your-username/today_ai_weather-base:main
|
|
||||||
FROM ${BASE_IMAGE} AS base
|
|
||||||
|
|
||||||
# Rails app lives here
|
|
||||||
WORKDIR /rails
|
|
||||||
|
|
||||||
# Install base packages, Move to Base Dockerfile.
|
|
||||||
|
|
||||||
# Set production environment
|
|
||||||
ENV RAILS_ENV="production" \
|
|
||||||
BUNDLE_DEPLOYMENT="1" \
|
|
||||||
BUNDLE_PATH="/usr/local/bundle" \
|
|
||||||
BUNDLE_WITHOUT="development"
|
|
||||||
|
|
||||||
# Throw-away build stage to reduce size of final image
|
|
||||||
FROM base AS build
|
|
||||||
|
|
||||||
# Install packages needed to build gems and node modules
|
|
||||||
RUN apt-get update -qq && \
|
|
||||||
apt-get install --no-install-recommends -y build-essential git node-gyp pkg-config python-is-python3 libpq-dev && \
|
|
||||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
||||||
|
|
||||||
# Install JavaScript dependencies
|
|
||||||
ARG NODE_VERSION=20.17.0
|
|
||||||
ARG YARN_VERSION=1.22.22
|
|
||||||
ENV PATH=/usr/local/node/bin:$PATH
|
|
||||||
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
|
|
||||||
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
|
|
||||||
npm install -g yarn@$YARN_VERSION && \
|
|
||||||
rm -rf /tmp/node-build-master
|
|
Loading…
Reference in New Issue
Block a user