Skip to content
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

feat: adding slim dockerfile #2219

Merged
merged 47 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
342b75b
feat: adding slim dockerfile
johnson2427 Aug 13, 2024
fd99375
feat: build slim first then recommended plugins
johnson2427 Aug 13, 2024
a166762
fix: install with root
johnson2427 Aug 13, 2024
ee5bcb2
feat: fix name label
johnson2427 Aug 14, 2024
1684984
feat: adding build and push to ghcr
johnson2427 Aug 14, 2024
c38dffe
fix: bad line in build and push
johnson2427 Aug 14, 2024
36a7fd9
fix: broken tags
johnson2427 Aug 15, 2024
08969bd
fix: clean up slim
johnson2427 Aug 15, 2024
1b56b97
fix: change workflow name for release
johnson2427 Aug 15, 2024
c13443d
fix: dont need to checkout twice
johnson2427 Aug 15, 2024
e281b40
fix: cleanup labels in slim
johnson2427 Aug 15, 2024
b1b3015
fix: broken dockerfile install
johnson2427 Aug 15, 2024
d487efd
feat: add fetch tags to checkout
johnson2427 Aug 15, 2024
f3ddc94
feat: remove tag checkout step
johnson2427 Aug 15, 2024
418a575
feat: adding attestations
johnson2427 Aug 15, 2024
71b85ab
feat: add a push to main build push as well
johnson2427 Aug 15, 2024
2a66fe9
feat: use proper tagging and dont push unless merge
johnson2427 Aug 15, 2024
fee78bc
feat: add cache build and build args
johnson2427 Aug 15, 2024
6278f4d
feat: properly cache
johnson2427 Aug 15, 2024
0a0d466
fix: try dockerbuildkit env
johnson2427 Aug 15, 2024
d2c01f9
fix: cannot cache containers with docker driver
johnson2427 Aug 15, 2024
6a401a9
fix: slim_image arg
johnson2427 Aug 15, 2024
998a0ea
fix: debugging
johnson2427 Aug 15, 2024
fa84360
fix: bad debug
johnson2427 Aug 15, 2024
f10a273
feat: fetch depth 0
johnson2427 Aug 15, 2024
9e36175
feat: remove debug
johnson2427 Aug 15, 2024
66e8b66
feat: fix versioning add debug feature back
johnson2427 Aug 16, 2024
6abd567
fix: need slim tag on pr
johnson2427 Aug 16, 2024
7ac14dd
feat: add oci
johnson2427 Aug 16, 2024
e050a25
feat: add commit sha and build date
johnson2427 Aug 16, 2024
8d1f6e9
fix: bad yaml
johnson2427 Aug 16, 2024
4affe4c
fix: move env variables to build args
johnson2427 Aug 16, 2024
12dc609
fix: use builtin github for sha
johnson2427 Aug 16, 2024
be9fc35
fix: date
johnson2427 Aug 16, 2024
465ccf4
fix: env var call
johnson2427 Aug 16, 2024
4728366
fix: date
johnson2427 Aug 16, 2024
d96958d
feat: remove args
johnson2427 Aug 16, 2024
165cb55
fix: version may have been the issue
johnson2427 Aug 16, 2024
9ac3971
feat: try without version
johnson2427 Aug 16, 2024
0ba38c8
feat: add version back
johnson2427 Aug 16, 2024
7b26a14
feat: adding docker command help in readme
johnson2427 Aug 19, 2024
b75a784
fix: update README.md
johnson2427 Aug 19, 2024
18fe554
fix: recommended-plugins should be installed
johnson2427 Aug 19, 2024
36387fa
fix: note
johnson2427 Aug 19, 2024
32b8afd
fix: mdformat issue
johnson2427 Aug 19, 2024
c43bd44
fix: update README.md
johnson2427 Aug 19, 2024
054e602
fix: note
johnson2427 Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/build.yaml
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Container Images
on:
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
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

johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
- 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
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
tags: ${{ steps.meta.outputs.tags }}-slim
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
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
41 changes: 14 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,30 @@
# See LICENSE in the project root for license information.
#---------------------------------------------------------------------------------------------

ARG SLIM_IMAGE
ARG PYTHON_VERSION="3.11"
ARG PLUGINS_FILE="./recommended-plugins.txt"

FROM python:${PYTHON_VERSION} as builder
FROM python:${PYTHON_VERSION} AS builder

WORKDIR /wheels

COPY ./recommended-plugins.txt ./recommended-plugins.txt
RUN pip install --upgrade pip \
&& pip install wheel

COPY . .

RUN pip install --upgrade pip \
&& pip install wheel \
&& pip wheel .[recommended-plugins] --wheel-dir=/wheels
COPY ./recommended-plugins.txt ./recommended-plugins.txt

FROM python:${PYTHON_VERSION}-slim
RUN pip wheel .[recommended-plugins] --wheel-dir=/wheels

# See http://label-schema.org for metadata schema
# TODO: Add `build-date` and `version`
LABEL maintainer="ApeWorX" \
org.label-schema.schema-version="2.0" \
org.label-schema.name="ape" \
org.label-schema.description="Ape Ethereum Framework." \
org.label-schema.url="https://docs.apeworx.io/ape/stable/" \
org.label-schema.usage="https://docs.apeworx.io/ape/stable/userguides/quickstart.html#via-docker" \
org.label-schema.vcs-url="https://github.com/ApeWorX/ape" \
org.label-schema.docker.cmd="docker run --volume $HOME/.ape:/home/harambe/.ape --volume $HOME/.vvm:/home/harambe/.vvm --volume $HOME/.solcx:/home/harambe/.solcx --volume $PWD:/home/harambe/project --workdir /home/harambe/project apeworx/ape compile"
FROM ${SLIM_IMAGE} AS ape_slim

RUN useradd --create-home --shell /bin/bash harambe
USER root

COPY --from=builder /wheels /wheels
COPY ./recommended-plugins.txt ./recommended-plugins.txt
COPY --from=builder /wheels/*.whl /wheels/

RUN pip install --upgrade pip \
pip install --no-cache-dir --find-links=/wheels -r ./recommended-plugins.txt \
&& ape --version
RUN pip install --upgrade pip
RUN pip install /wheels/*.whl

WORKDIR /home/harambe/project
RUN chown --recursive harambe:harambe /home/harambe
USER harambe
ENTRYPOINT ["ape"]

RUN ape --version
47 changes: 47 additions & 0 deletions Dockerfile.slim
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`
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
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"]
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,32 @@ There are three ways to install ape: `pipx`, `pip`, or `Docker`.

Ape can also run in a docker container.

Please visit our [Dockerhub](https://hub.docker.com/repository/docker/apeworx/ape) for more details on using Ape with Docker.
You can pull our images from [ghcr](https://ghcr.io/apeworx/ape).
This image is built using our `recommended-plugins` extra, so it is a great starting point for running ape in a containerized environment.

We also have a `slim` docker image that is built without any installed plugins.
This image is meant for production support and must be further configured if any plugins are in use.

You can pull the image:

```bash
$ docker pull ghcr.io/apeworx/ape:latest # installs with recommended-plugins
```

or pull the slim if you have specific needs that you'd like to build from:

```bash
$ docker pull ghcr.io/apeworx/ape:latest-slim # installs ape with required packages
```

or build the image locally from source:

```bash
$ docker build -t ape:latest-slim -f Dockerfile.slim .
$ docker build -t ape:latest .
```

An example of running a command from the container would be:

```bash
docker run \
Expand All @@ -70,6 +95,9 @@ docker run \
apeworx/ape compile
```

> **Note:**
> The above command requires the full install which includes `recommended-plugins` installation extra.

## Quickstart

After you have installed Ape, run `ape --version` to verify the installation was successful.
Expand Down
Loading