Skip to content

ci: add docker build args to repo selection #5

ci: add docker build args to repo selection

ci: add docker build args to repo selection #5

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.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 }}/${{ 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.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 }}/${{ 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.app
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
REPO=ghcr.io/${{ github.actor }}/${{ github.repository }}/${{ env.APP_NAME }}