Build and push Docker images #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'appex/**' | |
- 'requirements.txt' | |
- 'Dockerfile*' | |
workflow_dispatch: | |
jobs: | |
build: | |
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.build-deps-pex.outputs.cache-hit != 'true' | |
id: build-deps-docker | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: "ghcr.io/${{ github.repository }}/appex: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 appex | |
- name: Build and push src | |
if: steps.build-src-pex.outputs.cache-hit != 'true' | |
uses: docker/build-push-action@v5 | |
id: build-src-docker | |
with: | |
context: . | |
push: true | |
tags: "ghcr.io/${{ github.repository }}/appex: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 }}/appex:app" | |
file: Dockerfile.app | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |