-
Notifications
You must be signed in to change notification settings - Fork 3
72 lines (65 loc) · 2.34 KB
/
build.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
71
72
name: 🐳 Build And Push Docker Image
on:
workflow_call:
inputs:
tag:
type: string
description: The tag to push to the Docker registry.
# required: true
# default: latest
jobs:
build:
name: 🐳 Build
# only build/deploy main branch on pushes
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }}
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/[email protected]
- name: 🧑💻 Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true
- name: 🐳 Set up Docker Buildx
uses: docker/[email protected]
# Setup cache
- name: ⚡️ Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-buildx-
- name: 🐳 Build Production Image
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/[email protected]
with:
context: .
push: true
tags: algomax/nestjs-chat-api:production
build-args: |
COMMIT_SHA=${{ github.sha }} \
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: 🐳 Build Staging Image
if: ${{ github.ref == 'refs/heads/dev' }}
uses: docker/[email protected]
with:
context: .
push: true
tags: algomax/nestjs-chat-api:latest
build-args: |
COMMIT_SHA=${{ github.sha }} \
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# This ugly bit is necessary if you don't want your cache to grow forever
# till it hits GitHub's limit of 5GB.
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🚚 Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache