Skip to content

Commit 838a0c8

Browse files
authored
Merge pull request #256 from orionrobots/copilot/fix-255
Add Docker base image caching to reduce build times
2 parents 1c23d30 + a8e9bf6 commit 838a0c8

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.github/workflows/on_call_build_site.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
on:
33
workflow_call:
4+
inputs:
5+
push_tag:
6+
description: 'Tag to push the base image with (optional)'
7+
required: false
8+
type: string
49

510
jobs:
611
build_site:
@@ -24,6 +29,10 @@ jobs:
2429
username: ${{ github.actor }}
2530
password: ${{ github.token }}
2631

32+
- name: Build base image
33+
run: |
34+
docker build --target base -t ghcr.io/orionrobots/orionrobots-site.base:${{ inputs.push_tag || 'temp' }} .
35+
2736
- name: Build the site with docker compose
2837
run: |
2938
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --build build
@@ -45,3 +54,8 @@ jobs:
4554
name: httpd.conf
4655
path: .github/scripts/staging/httpd.conf
4756
if-no-files-found: error
57+
58+
- name: Push base image
59+
if: inputs.push_tag
60+
run: |
61+
docker push ghcr.io/orionrobots/orionrobots-site.base:${{ inputs.push_tag }}

.github/workflows/on_pr_test.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,32 @@ on:
3131
- 'docker-compose.yml'
3232

3333
jobs:
34+
detect_base_image_changes:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
changed: ${{ steps.changes.outputs.any_changed }}
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Check for base image related changes
42+
# tj-actions/changed-files v44.5.7
43+
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
44+
id: changes
45+
with:
46+
files: |
47+
Dockerfile
48+
package.json
49+
package-lock.json
50+
.github/workflows/on_call_build_site.yaml
51+
.github/workflows/on_pr_test.yaml
52+
3453
build_site:
54+
needs: detect_base_image_changes
3555
uses: ./.github/workflows/on_call_build_site.yaml
56+
with:
57+
push_tag: >-
58+
${{ needs.detect_base_image_changes.outputs.changed == 'true'
59+
&& github.event.number || '' }}
3660
3761
staging_test:
3862
uses: ./.github/workflows/on_call_staging_test.yaml

.github/workflows/on_push_to_master_test_and_deploy.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ concurrency:
3636
jobs:
3737
build_site:
3838
uses: ./.github/workflows/on_call_build_site.yaml
39+
with:
40+
push_tag: "latest"
3941

4042
staging_test:
4143
uses: ./.github/workflows/on_call_staging_test.yaml
@@ -85,12 +87,13 @@ jobs:
8587

8688
- uses: actions/checkout@v4
8789

88-
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
90+
- name: Check for workflow changes
91+
# tj-actions/changed-files v44.5.7
92+
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
8993
id: filter
9094
with:
91-
filters: |
92-
workflows:
93-
- '.github/workflows/**'
95+
files: |
96+
.github/workflows/**
9497
9598
# see https://github.com/mcdeck/netlify-cms-oauth-provider-php
9699
- name: Checkout the netlify-cms-oauth-provider-php
@@ -100,13 +103,13 @@ jobs:
100103
path: netlify-cms-oauth-provider-php
101104

102105
- name: Perform the netlify composer install
103-
if: steps.filter.outputs.workflows == 'true'
106+
if: steps.filter.outputs.any_changed == 'true'
104107
run: |
105108
cd netlify-cms-oauth-provider-php
106109
composer install
107110
108111
- name: Copy over the netlify-cms-oauth-provider-php files
109-
if: steps.filter.outputs.workflows == 'true'
112+
if: steps.filter.outputs.any_changed == 'true'
110113
uses: burnett01/rsync-deployments@3cccb6851148e6198ed9ed89eb0d1c17b5e58cc7 # v7.0.2
111114
with:
112115
switches: -a
@@ -117,7 +120,7 @@ jobs:
117120
remote_key: ${{ secrets.ORIONROBOTS_DEPLOY_KEY }}
118121

119122
- name: Create the oauth environment file
120-
if: steps.filter.outputs.workflows == 'true'
123+
if: steps.filter.outputs.any_changed == 'true'
121124
run: |
122125
(
123126
echo "OAUTH_CLIENT_ID=${{ secrets.ORIONROBOTS_OAUTH_CLIENT_ID }}"
@@ -128,7 +131,7 @@ jobs:
128131
) > netlify-cms-oauth-provider-php/.env.local
129132
130133
- name: Copy over the oauth environment file
131-
if: steps.filter.outputs.workflows == 'true'
134+
if: steps.filter.outputs.any_changed == 'true'
132135
uses: burnett01/rsync-deployments@3cccb6851148e6198ed9ed89eb0d1c17b5e58cc7 # v7.0.2
133136
with:
134137
switches: -a

0 commit comments

Comments
 (0)