Skip to content

Commit 48fd1ba

Browse files
authored
Merge pull request #611 from cornell-dti/bek76/docker-ci
Push Docker images to ghcr on PR events & deduplicate Docker build logic
2 parents ba5544f + 62b3971 commit 48fd1ba

3 files changed

Lines changed: 88 additions & 30 deletions

File tree

.github/workflows/cd-workflow.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,10 @@ on:
66

77
jobs:
88
deploy:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Checkout code
12-
uses: actions/checkout@v2
13-
14-
- name: Set up Docker Buildx
15-
uses: docker/setup-buildx-action@v2
16-
17-
- name: Login to Docker Hub
18-
uses: docker/login-action@v2
19-
with:
20-
username: ${{ secrets.DOCKERHUB_USERNAME }}
21-
password: ${{ secrets.DOCKERHUB_TOKEN }}
22-
23-
- name: Build and push Docker image
24-
uses: docker/build-push-action@v4
25-
with:
26-
push: true
27-
build-args: |
28-
REACT_APP_SERVER_URL=${{ secrets.REACT_APP_SERVER_URL }}
29-
REACT_APP_CLIENT_ID=${{ secrets.REACT_APP_CLIENT_ID }}
30-
REACT_APP_PUBLIC_VAPID_KEY=${{ secrets.REACT_APP_PUBLIC_VAPID_KEY }}
31-
REACT_APP_ENCRYPTION_KEY=${{ secrets.REACT_APP_ENCRYPTION_KEY }}
32-
tags: dticarriage/carriage-service:latest
9+
uses: ./.github/workflows/docker-build-push.yml
10+
with:
11+
push: true
12+
tags: dticarriage/carriage-service:latest
13+
registry: docker.io
14+
username: ${{ secrets.DOCKERHUB_USERNAME }}
15+
password: ${{ secrets.DOCKERHUB_TOKEN }}

.github/workflows/ci-container.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ on: pull_request
44

55
jobs:
66
build:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- name: Set up Docker Buildx
10-
uses: docker/setup-buildx-action@v2
11-
- name: Build Docker image
12-
uses: docker/build-push-action@v4
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
uses: ./.github/workflows/docker-build-push.yml
12+
with:
13+
push: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
14+
tags: |
15+
ghcr.io/${{ github.repository }}/pr-${{ github.event.pull_request.number }}:latest
16+
ghcr.io/${{ github.repository }}/pr-${{ github.event.pull_request.number }}:${{ github.sha }}
17+
labels: |
18+
org.opencontainers.image.source=${{ github.event.pull_request.html_url }}
19+
org.opencontainers.image.title=PR-${{ github.event.pull_request.number }}
20+
org.opencontainers.image.description=${{ github.event.pull_request.title }}
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
push:
7+
description: 'Whether to push the image'
8+
required: true
9+
type: boolean
10+
tags:
11+
description: 'Image tags to apply'
12+
required: true
13+
type: string
14+
labels:
15+
description: 'Optional image labels'
16+
required: false
17+
default: ''
18+
type: string
19+
registry:
20+
description: 'Registry URL (optional)'
21+
required: false
22+
type: string
23+
username:
24+
description: 'Registry password (optional)'
25+
required: false
26+
type: string
27+
password:
28+
description: 'Registry password (optional)'
29+
required: false
30+
type: string
31+
32+
jobs:
33+
build:
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v5
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Log in to registry
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ inputs.registry }}
47+
username: ${{ inputs.username }}
48+
password: ${{ inputs.password }}
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v6
52+
with:
53+
push: ${{ inputs.push }}
54+
tags: ${{ inputs.tags }}
55+
labels: ${{ inputs.labels }}
56+
cache-from: type=gha
57+
cache-to: type=gha,mode=max
58+
build-args: |
59+
REACT_APP_SERVER_URL=${{ secrets.REACT_APP_SERVER_URL }}
60+
REACT_APP_CLIENT_ID=${{ secrets.REACT_APP_CLIENT_ID }}
61+
REACT_APP_PUBLIC_VAPID_KEY=${{ secrets.REACT_APP_PUBLIC_VAPID_KEY }}
62+
REACT_APP_ENCRYPTION_KEY=${{ secrets.REACT_APP_ENCRYPTION_KEY }}
63+
REACT_APP_GOOGLE_MAPS_API_KEY=${{ secrets.REACT_APP_GOOGLE_MAPS_API_KEY }}
64+
REACT_APP_GOOGLE_MAPS_MAP_ID=${{ secrets.REACT_APP_GOOGLE_MAPS_MAP_ID }}

0 commit comments

Comments
 (0)