-
Notifications
You must be signed in to change notification settings - Fork 2
70 lines (62 loc) · 1.95 KB
/
build-and-push-dockerhub.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Build and push to Dockerhub
on:
workflow_call:
inputs:
repo:
type: string
required: false
default: "codecov"
cache:
type: boolean
default: true
image_name:
type: string
required: true
docker_path:
type: string
required: true
push:
type: boolean
default: true
description: "Whether to push the image"
env:
DOCKERHUB_REPO: ${{ inputs.repo }}
IMAGE_NAME: ${{ inputs.image_name }}
DOCKER_PATH: ${{ inputs.docker_path }}
jobs:
build-and-push:
name: Build and push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Image
id: cache-image
if: inputs.cache
uses: actions/cache@v4
env:
cache-name: cache-${{ inputs.image_name }}
with:
path: |
${{ inputs.image_name }}.tar
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.run_id }}
- name: Load built image
if: ${{ inputs.cache && steps.cache-image.outputs.cache-hit == 'true' }}
run: |
make load.${{ inputs.image_name }}
- name: Build image
if: ${{ !inputs.cache || steps.cache-image.outputs.cache-hit != 'true' }}
run: |
make build.${{ inputs.image_name }}
make save.${{ inputs.image_name }}
- name: Log in to Docker Hub
uses: docker/[email protected]
if: ${{ inputs.push && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
with:
username: ${{ secrets.CODECOV_DEVOPS_DOCKER_USERNAME }}
password: ${{ secrets.CODECOV_DEVOPS_DOCKER_PASSWORD }}
- name: Push image
if: ${{ inputs.push && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
make tag.${{ inputs.image_name }}
make push.${{ inputs.image_name }}