-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (93 loc) · 2.84 KB
/
build_and_push.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
on:
push:
branches:
- main
paths:
- 'appex/**'
- 'requirements.txt'
- 'Dockerfile*'
workflow_dispatch:
name: Build and push Docker images
jobs:
build-and-push:
env:
APP_NAME: appex
name: Build and push Docker images
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: .github/ci-requirements.txt
- name: Install PEX
id: install-pex
run: pip install pex
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v3
id: cache-deps
with:
path: build/deps.pex
key: ${{ runner.os }}-deps-pex-${{ hashFiles('requirements.txt') }}
- name: Build deps PEX
id: build-deps-pex
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
pex -r requirements.txt -o build/deps.pex \
--include-tools \
--layout=packed
- name: Build and push deps
if: steps.cache-deps.outputs.cache-hit != 'true'
id: build-deps-docker
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: "ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:deps"
file: Dockerfile.deps
cache-from: type=gha
cache-to: type=gha,mode=max
- uses: actions/cache@v3
id: cache-src
with:
path: build/src.pex
key: ${{ runner.os }}-src-pex-${{ hashFiles('appex/**') }}
- name: Build src PEX
id: build-src-pex
if: steps.cache-src.outputs.cache-hit != 'true'
run: |
pex -o build/src.pex --include-tools \
--layout=packed -P ${{ env.APP_NAME }}
- name: Build and push src
if: steps.cache-src.outputs.cache-hit != 'true'
uses: docker/build-push-action@v5
id: build-src-docker
with:
context: .
push: true
tags: "ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:src"
file: Dockerfile.src
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push app
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: "ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:app"
file: Dockerfile.deploy
cache-from: type=gha
cache-to: type=gha,mode=max