Skip to content

Commit 96013e9

Browse files
committed
Update workflows: main based on base image
1 parent 0c16082 commit 96013e9

File tree

3 files changed

+97
-29
lines changed

3 files changed

+97
-29
lines changed

.github/workflows/MAIN_IMAGE_README.md

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Main Rails Docker Image Build Workflows
22

3-
Two GitHub Actions workflows for automatic building and publishing Main Rails image in multi-arch (ARM64, AMD64, and ARM/v7).
3+
Two GitHub Actions workflows for automatic building and publishing Main Rails image in multi-arch (ARM64 and AMD64).
44

55
## 🎯 Key Feature: Flexible Base Image Selection
66

@@ -15,15 +15,24 @@ Main image can be built from **two different sources**:
1515

1616
### 1. `docker-main-image.yml` - GHCR (GitHub Container Registry)
1717

18-
**Triggers:**
18+
**Triggers (in priority order):**
19+
20+
1.**After Base Image Build** (`workflow_run`)
21+
22+
- Waits for `Build and Push Base Docker Image` to complete successfully
23+
- Automatically starts building Main after Base is ready
24+
- Ensures Main uses fresh Base image
25+
26+
2. 🔄 **Push to branch** (when Main or workflow files change)
1927

20-
- 🔄 Push to `main` or `master` branches (if files in `docker/IMAGES/` changed)
21-
- 🔄 Pull Request to `main` or `master` branches
22-
- ⚙️ Manual run (workflow_dispatch) - allows selecting base image source
28+
- Direct trigger if Base hasn't changed
29+
30+
3. ⚙️ **Manual run** (workflow_dispatch)
31+
- Choose base image source manually
2332

2433
**What it does:**
2534

26-
- ✅ Builds image for `linux/amd64`, `linux/arm64`, and `linux/arm/v7`
35+
- ✅ Builds image for `linux/amd64` and `linux/arm64`
2736
- 📤 Pushes to GitHub Container Registry (ghcr.io)
2837
- 💾 Caches layers to speed up future builds
2938
- 🏷️ Automatically generates tags (branch, SHA, latest)
@@ -62,7 +71,7 @@ FROM ghcr.io/the-teacher/rails-start.main:latest
6271

6372
**What it does:**
6473

65-
- ✅ Builds image for `linux/amd64`, `linux/arm64`, and `linux/arm/v7`
74+
- ✅ Builds image for `linux/amd64` and `linux/arm64`
6675
- 📤 Pushes to Docker Hub
6776
- 🔀 Allows choosing base image source (GHCR or Docker Hub)
6877

@@ -110,11 +119,10 @@ Uses `${{ secrets.GITHUB_TOKEN }}` - automatically available.
110119

111120
## 🏗️ Supported Architectures
112121

113-
| Architecture | Usage |
114-
| ---------------- | -------------------------------------- |
115-
| **linux/amd64** | Intel/AMD 64-bit (desktops, servers) |
116-
| **linux/arm64** | ARM 64-bit (M1/M2 Mac, modern servers) |
117-
| **linux/arm/v7** | ARM 32-bit (Raspberry Pi, legacy ARM) |
122+
| Architecture | Usage |
123+
| --------------- | -------------------------------------- |
124+
| **linux/amd64** | Intel/AMD 64-bit (desktops, servers) |
125+
| **linux/arm64** | ARM 64-bit (M1/M2 Mac, modern servers) |
118126

119127
---
120128

@@ -133,18 +141,50 @@ Uses `${{ secrets.GITHUB_TOKEN }}` - automatically available.
133141

134142
## 🚀 Typical Workflow
135143

144+
### Automatic Build Chain (Recommended)
145+
146+
```
147+
1. You push changes to docker/IMAGES/_Base.Dockerfile
148+
149+
2. GitHub automatically triggers Base workflow
150+
151+
3. Base image builds for arm64 + amd64
152+
153+
4. Base image pushes to ghcr.io successfully
154+
155+
5. Main workflow AUTOMATICALLY triggered (workflow_run)
156+
157+
6. Main image builds using fresh Base image
158+
159+
7. Main image pushes to ghcr.io
160+
```
161+
162+
**Result:** Main always uses the latest Base image! ✅
163+
136164
### Development (GHCR)
137165

138166
```bash
139-
# Improve Main Dockerfile
140-
git commit -am "Add new tools to Main image"
167+
# Improve Base Dockerfile
168+
git commit -am "Add new tools to Base image"
141169
git push origin master
142170

143-
# → GHA automatically (using GHCR base):
144-
# 1. Pulls ghcr.io/the-teacher/rails-start.base:latest
145-
# 2. Builds image for arm64 + amd64 + arm/v7
146-
# 3. Pushes to ghcr.io
147-
# 4. Caches layers
171+
# → GHA automatically:
172+
# 1. Builds Base image for arm64 + amd64
173+
# 2. Pushes to ghcr.io
174+
# 3. Main workflow starts automatically
175+
# 4. Builds Main using new Base
176+
# 5. Pushes Main to ghcr.io
177+
```
178+
179+
### Manual Build with specific Base
180+
181+
```bash
182+
# If you want to rebuild Main with specific Base source:
183+
# 1. GitHub → Actions
184+
# 2. "Build and Push Main Docker Image"
185+
# 3. "Run workflow"
186+
# 4. Choose Base image source (ghcr or dockerhub)
187+
# 5. "Run workflow"
148188
```
149189

150190
### Release (Docker Hub)

.github/workflows/docker-main-hub.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
with:
7272
context: ./docker/IMAGES
7373
file: ./docker/IMAGES/_Main.Dockerfile
74-
platforms: linux/amd64,linux/arm64,linux/arm/v7
74+
platforms: linux/amd64,linux/arm64
7575
push: true
7676
tags: ${{ steps.tags.outputs.tags }}
7777
build-args: |

.github/workflows/docker-main-image.yml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
name: Build and Push Main Docker Image
22

33
on:
4-
push:
5-
branches: ["main", "master"]
6-
paths:
7-
- "docker/IMAGES/_Main.Dockerfile"
8-
- ".github/workflows/docker-main-image.yml"
9-
pull_request:
4+
# Trigger after Base image workflow completes successfully
5+
workflow_run:
6+
workflows: ["Build and Push Base Docker Image"]
7+
types:
8+
- completed
109
branches: ["main", "master"]
11-
paths:
12-
- "docker/IMAGES/_Main.Dockerfile"
10+
# Also allow manual trigger
1311
workflow_dispatch:
1412
inputs:
1513
base_image_source:
@@ -20,15 +18,45 @@ on:
2018
options:
2119
- ghcr
2220
- dockerhub
21+
# Allow manual builds when Base Dockerfile or this workflow changes
22+
push:
23+
branches: ["main", "master"]
24+
paths:
25+
- "docker/IMAGES/_Main.Dockerfile"
26+
- ".github/workflows/docker-main-image.yml"
27+
pull_request:
28+
branches: ["main", "master"]
29+
paths:
30+
- "docker/IMAGES/_Main.Dockerfile"
2331

2432
env:
2533
REGISTRY: ghcr.io
2634
IMAGE_NAME: ${{ github.repository_owner }}/rails-start.main
2735
DOCKERHUB_IMAGE_NAME: iamteacher/rails-start.main
2836

2937
jobs:
38+
check-base:
39+
name: Check Base Image Build Status
40+
runs-on: ubuntu-latest
41+
if: github.event_name == 'workflow_run'
42+
steps:
43+
- name: Verify Base workflow success
44+
run: |
45+
if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
46+
echo "❌ Base image build failed or was cancelled"
47+
exit 1
48+
fi
49+
echo "✅ Base image built successfully"
50+
3051
build:
52+
name: Build Main Image
3153
runs-on: ubuntu-latest
54+
needs: [check-base]
55+
if: |
56+
always() && (
57+
github.event_name != 'workflow_run' ||
58+
needs.check-base.result == 'success'
59+
)
3260
permissions:
3361
contents: read
3462
packages: write
@@ -93,7 +121,7 @@ jobs:
93121
with:
94122
context: ./docker/IMAGES
95123
file: ./docker/IMAGES/_Main.Dockerfile
96-
platforms: linux/amd64,linux/arm64,linux/arm/v7
124+
platforms: linux/amd64,linux/arm64
97125
push: ${{ github.event_name != 'pull_request' }}
98126
tags: ${{ steps.meta.outputs.tags }}
99127
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)