generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: dockerfile uses ape slim and add build yaml #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d955882
feat: fix dockerfile and add build yaml
johnson2427 b41d3f3
fix: Dockerfile should allow for version arg
johnson2427 4315492
fix: allow build arg in build
johnson2427 b119a6b
feat: test workflow
johnson2427 49a8981
fix: tags
johnson2427 d9af9f6
fix: swtich ape_version to base_ape_image_tag
johnson2427 d95c7ae
fix: use stable-slim release
johnson2427 1a037b7
feat: build with latest-slim
johnson2427 b557fac
feat: only keep last minor
johnson2427 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,117 @@ | ||
name: Container Images | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
release: | ||
type: [published] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
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 | ||
|
||
- name: Show tags | ||
run: | | ||
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/') | ||
run: echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV | ||
|
||
- name: Log into GitHub Container Registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
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/container-retention-policy@v3.0.0 | ||
with: | ||
account: ApeWorX | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
image-tags: "!stable* !latest* !${{ env.keep_tags }}" | ||
tag-selection: both | ||
cut-off: 4w | ||
dry-run: true | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.