-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Docker build CI * build on main branch and release only * always push * build on pull request
- Loading branch information
Showing
4 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
name: Build Docker | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
branches: | ||
- 'main' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
|
||
jobs: | ||
docker-build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Setup Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Generate Docker metadata for ghcr.io | ||
id: meta-ghcr | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=ref,event=pr | ||
type=pep440,pattern={{version}} | ||
type=pep440,pattern={{major}} | ||
type=pep440,pattern={{major}}.{{minor}} | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Generate Docker build cache source metadata | ||
id: meta-buildcache-source | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=raw,value=latest,suffix=-buildcache | ||
- name: Generate Docker build cache destination metadata | ||
id: meta-buildcache-destination | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=raw,value=latest,suffix=-buildcache,enable={{is_default_branch}} | ||
- name: Generate Docker build cache metadata vars | ||
id: meta-buildcache-vars | ||
shell: bash | ||
env: | ||
DOCKER_METADATA_BUILDCACHE_SOURCE_OUTPUT_JSON: ${{ steps.meta-buildcache-source.outputs.json }} | ||
DOCKER_METADATA_BUILDCACHE_DESTINATION_OUTPUT_JSON: ${{ steps.meta-buildcache-destination.outputs.json }} | ||
run: | | ||
{ | ||
echo "cache-from<<EOF" | ||
for tag in $(jq -r '.tags[]' <<< "$DOCKER_METADATA_BUILDCACHE_SOURCE_OUTPUT_JSON"); do | ||
echo "type=registry,ref=${tag}" | ||
done | ||
echo "EOF" | ||
} >> $GITHUB_OUTPUT | ||
{ | ||
echo "cache-to<<EOF" | ||
for tag in $(jq -r '.tags[]' <<< "$DOCKER_METADATA_BUILDCACHE_DESTINATION_OUTPUT_JSON"); do | ||
echo "type=registry,ref=${tag},mode=max" | ||
done | ||
echo "EOF" | ||
} >> $GITHUB_OUTPUT | ||
- name: Login to GitHub Container Registry (ghcr.io) | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: 'ghcr.io' | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Replace Version | ||
shell: bash | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: | | ||
TAG="${{ github.ref_name }}" | ||
# strip first char 'v' | ||
VERSION=${TAG:1} | ||
sed -i "s/__version__ = \"0.0.0\"/__version__ = \"${VERSION}\"/" amaterus_announce_image_downloader/__init__.py | ||
sed -i "s/version = \"0.0.0\"/version = \"${VERSION}\"/" pyproject.toml | ||
- name: Build and Deploy Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: . | ||
file: ./Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
platforms: | | ||
linux/amd64 | ||
linux/arm64 | ||
tags: | | ||
${{ steps.meta-ghcr.outputs.tags }} | ||
cache-from: ${{ steps.meta-buildcache-vars.outputs.cache-from }} | ||
cache-to: ${{ steps.meta-buildcache-vars.outputs.cache-to }} | ||
labels: ${{ steps.meta-ghcr.outputs.labels }} | ||
annotations: ${{ steps.meta-ghcr.outputs.annotations }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__VERSION__ = "0.1.0" | ||
__version__ = "0.0.0" |
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
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