2023-02-25 17:14:05 +00:00
|
|
|
# todo: use https://github.com/jpribyl/action-docker-layer-caching
|
|
|
|
# todo: make this generic for all Rust images in this repo
|
|
|
|
# todo: don't use docker/build-push-action
|
|
|
|
# todo: run builds on pull request
|
|
|
|
|
2023-02-16 00:27:36 +00:00
|
|
|
name: Build and push API Docker image
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths:
|
|
|
|
- 'lib/pklib/**'
|
|
|
|
- 'services/api/**'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
packages: write
|
|
|
|
if: github.repository == 'PluralKit/PluralKit'
|
|
|
|
steps:
|
|
|
|
- uses: docker/login-action@v1
|
2023-02-26 22:13:56 +00:00
|
|
|
if: ${{ !env.ACT }}
|
2023-02-16 00:27:36 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.CR_PAT }}
|
2023-02-26 22:13:56 +00:00
|
|
|
|
2023-02-16 00:27:36 +00:00
|
|
|
- uses: actions/checkout@v2
|
2023-02-26 22:13:56 +00:00
|
|
|
- uses: docker/setup-buildx-action@v1
|
|
|
|
|
|
|
|
# main docker build
|
2023-02-16 00:27:36 +00:00
|
|
|
- run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
|
|
|
|
- uses: docker/build-push-action@v2
|
|
|
|
with:
|
|
|
|
# https://github.com/docker/build-push-action/issues/378
|
|
|
|
context: .
|
2023-02-25 17:14:05 +00:00
|
|
|
file: Dockerfile.rust
|
2023-02-26 22:13:56 +00:00
|
|
|
push: false
|
|
|
|
cache-from: type=gha
|
|
|
|
cache-to: type=gha
|
|
|
|
outputs: .docker-bin
|
|
|
|
|
|
|
|
# add more binaries here
|
|
|
|
- run: |
|
|
|
|
for binary in "api"; do
|
|
|
|
for tag in latest ${{ env.BRANCH_NAME }} ${{ github.sha }}; do
|
2023-03-19 15:20:57 +00:00
|
|
|
cat Dockerfile.bin | sed "s/__BINARY__/$binary/g" | docker build -t ghcr.io/pluralkit/$binary:$tag -f - .
|
2023-02-26 22:13:56 +00:00
|
|
|
done
|
|
|
|
if [ "${{ github.repository }}" == "PluralKit/PluralKit" ]; then
|
|
|
|
docker push ghcr.io/pluralkit/$binary:${{ env.BRANCH_NAME }}
|
|
|
|
docker push ghcr.io/pluralkit/$binary:${{ github.sha }}
|
|
|
|
[ "${{ env.BRANCH_NAME }}" == "main" ] && docker push ghcr.io/pluralkit/$binary:latest
|
|
|
|
fi
|
|
|
|
done
|