-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding slim dockerfile (#2219)
Co-authored-by: El De-dog-lo <[email protected]>
- Loading branch information
1 parent
6b56755
commit 7dd9d4c
Showing
4 changed files
with
170 additions
and
28 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,80 @@ | ||
name: Container Images | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
release: | ||
types: [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=ref,event=pr | ||
type=ref,event=branch,branch=main,latest=true | ||
type=ref,event=branch,branch=main | ||
type=ref,event=branch,branch!=main | ||
type=semver,pattern={{version}},branch=main,latest=false | ||
type=ref,event=tag | ||
- name: Show tags | ||
run: | | ||
git tag | ||
echo ${{ steps.meta.outputs.tags }} | ||
- 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 slim | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: ./Dockerfile.slim | ||
tags: ${{ steps.meta.outputs.tags }}-slim | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
BUILD_DATE=${{ github.event.repository.updated_at }} | ||
VCS_REF=${{ github.sha }} | ||
VERSION=${{ env.VERSION }} | ||
- 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: | | ||
SLIM_IMAGE=${{ steps.meta.outputs.tags }}-slim |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#--------------------------------------------------------------------------------------------- | ||
# See LICENSE in the project root for license information. | ||
#--------------------------------------------------------------------------------------------- | ||
|
||
ARG PYTHON_VERSION="3.11" | ||
|
||
FROM python:${PYTHON_VERSION} AS builder | ||
|
||
WORKDIR /wheels | ||
|
||
RUN pip install --upgrade pip \ | ||
&& pip install wheel | ||
|
||
COPY . . | ||
|
||
RUN pip wheel . | ||
|
||
FROM python:${PYTHON_VERSION}-slim | ||
|
||
# See http://label-schema.org for metadata schema | ||
# TODO: Add `build-date` and `version` | ||
LABEL org.opencontainers.image.title="ape" \ | ||
org.opencontainers.image.description="Ape Framework" \ | ||
org.opencontainers.image.url="https://apeworx.io/framework" \ | ||
org.opencontainers.image.documentation="https://docs.apeworx.io/ape/stable/userguides/quickstart.html\#installation" \ | ||
org.opencontainers.image.source="https://github.com/ApeWorX/ape" \ | ||
org.opencontainers.image.vendor="ApeWorX" \ | ||
org.opencontainers.image.licenses="Apache-2.0" \ | ||
org.opencontainers.image.version="${VERSION:-latest}" \ | ||
org.opencontainers.image.created="${BUILD_DATE}" \ | ||
org.opencontainers.image.revision="${VCS_REF}" \ | ||
org.opencontainers.image.authors="ApeWorX" \ | ||
org.opencontainers.image.base.name="python:${PYTHON_VERSION}-slim" | ||
|
||
|
||
RUN useradd --create-home --shell /bin/bash harambe | ||
COPY --from=builder /wheels/*.whl /wheels/ | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install /wheels/*.whl | ||
|
||
RUN ape --version | ||
|
||
WORKDIR /home/harambe/project | ||
RUN chown --recursive harambe:harambe /home/harambe | ||
USER harambe | ||
ENTRYPOINT ["ape"] |
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