Skip to content

Commit

Permalink
feat: build with latest-slim
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson2427 committed Sep 30, 2024
1 parent 2742420 commit 02f53de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
65 changes: 57 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=tag
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=ref,event=pr
type=ref,event=branch,branch=main,latest=true
type=ref,event=branch,branch=main,tag=latest
type=ref,event=branch,branch!=main
type=semver,pattern={{version}},branch=main,latest=false,tag=stable
type=ref,event=tag,tag={{ tag }}
- name: Show tags
run: |
git tag
echo ${{ steps.meta.outputs.tags }}
echo "Tags generated by metadata-action:\n"
for tag in ${{ steps.metadata.output.tags }}; do
echo $tag
done
- name: Extract version from tag
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -65,4 +65,53 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BASE_APE_IMAGE_TAG=stable-slim
BASE_APE_IMAGE_TAG=latest-slim
- name: Fetch all tags and store them
run: |
# List all tags
tags=$(git tag -l)
echo "All tags:"
echo "$tags"
# Save tags in an environment variable for later use
echo "ALL_TAGS=$(echo $tags | tr '\n' ' ')" >> $GITHUB_ENV
- name: Retain last two minor versions
run: |
# Fetch all tags in the format X.Y.Z
echo "Using stored tags..."
all_tags="${{ env.ALL_TAGS }}"
echo "All tags:"
echo "$all_tags"
# Extract the minor versions (X.Y) from tags in the format vX.X.X
latest_two_minors=$(echo "$all_tags" | tr ' ' '\n' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+$/\1/' | uniq | tail -n 2)
echo "Last two minor versions:"
echo "$latest_two_minors"
keep_tags=""
for minor in $latest_two_minors; do
echo "Processing minor version: $minor"
patches=$(echo "$all_tags" | tr ' ' '\n' | grep "^v$minor\.")
echo "Latest patch for $minor: $patches"
keep_tags="$keep_tags $patches"
done
# Store the tags in the environment variable
keep_tags=$(echo $keep_tags | tr ' ' '\n' | paste -sd ',' -)
echo "Tags to keep: $keep_tags"
echo "keep_tags=$keep_tags" >> $GITHUB_ENV
echo "keep_tags=$keep_tags"
- name: Run container retention policy
if: github.ref == 'refs/heads/main'
uses: snok/[email protected]
with:
account: ApeWorX
token: ${{ secrets.GITHUB_TOKEN }}
image-tags: "!stable* !latest* !${{ env.keep_tags }}"
tag-selection: both
cut-off: 4w
dry-run: true

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN pip install --upgrade pip && pip install wheel
RUN pip wheel . --wheel-dir=/wheels

# Install from wheels
FROM ghcr.io/apeworx/ape:${BASE_APE_IMAGE_TAG:-stable-slim}
FROM ghcr.io/apeworx/ape:${BASE_APE_IMAGE_TAG:-latest-slim}
USER root
COPY --from=builder /wheels /wheels
RUN pip install --upgrade pip \
Expand Down

0 comments on commit 02f53de

Please sign in to comment.