Skip to content

Commit

Permalink
Create a fork for magic
Browse files Browse the repository at this point in the history
  • Loading branch information
zbowling committed Nov 13, 2024
1 parent 086d025 commit eab5103
Show file tree
Hide file tree
Showing 12 changed files with 785 additions and 748 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @pavelzw
* @modular/magic
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
file: Dockerfile
token: ${{ secrets.GITHUB_TOKEN }}
version-extraction-override: 'regex:ARG PIXI_VERSION=(.*)'
version-extraction-override: 'regex:ARG MAGIC_VERSION=(.*)'
- name: Determine if pushing images
id: push
run: echo push=${{ steps.version-metadata.outputs.changed == 'true' && github.event_name == 'push' && github.ref_name == 'main' }} >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |-
ghcr.io/prefix-dev/pixi
ghcr.io/modular/magic
flavor: latest=false
# latest
# base-image
Expand Down Expand Up @@ -141,8 +141,8 @@ jobs:
if: needs.version.outputs.push == 'true'
run: |
docker images
docker run --rm ghcr.io/prefix-dev/pixi:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} pixi --version
docker run --rm ghcr.io/prefix-dev/pixi:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} sh -c "mkdir /app && cd /app && pixi init && pixi add python && pixi run python --version"
docker run --rm ghcr.io/modular/magic:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} magic --version
docker run --rm ghcr.io/modular/magic:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} sh -c "mkdir /app && cd /app && magic init && magic add python && magic run python --version"
- name: Image digest
run: echo ${{ steps.build.outputs.digest }}

Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/bump.yml

This file was deleted.

12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ARG PIXI_VERSION=0.36.0
ARG MAGIC_VERSION=0.4.0
ARG BASE_IMAGE=debian:bookworm-slim

FROM --platform=$TARGETPLATFORM ubuntu:24.04 AS builder
# need to specify the ARG again to make it available in this stage
ARG PIXI_VERSION
ARG MAGIC_VERSION
RUN apt-get update && apt-get install -y curl
# download the musl build since the gnu build is not available on aarch64
RUN curl -Ls \
"https://github.com/prefix-dev/pixi/releases/download/v${PIXI_VERSION}/pixi-$(uname -m)-unknown-linux-musl" \
-o /pixi && chmod +x /pixi
RUN /pixi --version
"https://dl.modular.com/public/magic/raw/versions/${MAGIC_VERSION}/magic-$(uname -m)-unknown-linux-musl" \
-o /magic && chmod +x /magic
RUN /magic --version

FROM --platform=$TARGETPLATFORM $BASE_IMAGE
COPY --from=builder --chown=root:root --chmod=0555 /pixi /usr/local/bin/pixi
COPY --from=builder --chown=root:root --chmod=0555 /magic /usr/local/bin/magic
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# pixi-docker
# magic-docker (based on pixi-docker)

This repository contains the docker configuration for the pixi container image.
The pixi container image is based on different base images, depending on the use case.
All images have pixi installed in `/usr/local/bin/pixi` and are ready to use.
This repository contains the docker configuration for the magic container image.
The magic container image is based on different base images, depending on the use case.
All images have pixi installed in `/usr/local/bin/magic` and are ready to use.

## Pulling the images

The images are [available on "GHCR" (Github Container Registry)](https://github.com/prefix-dev/pixi-docker/pkgs/container/pixi).
The images are [available on "GHCR" (Github Container Registry)](https://github.com/modular/magic-docker/pkgs/container/magic).
You can pull them using docker like so:

```bash
docker pull ghcr.io/prefix-dev/pixi:latest
docker pull ghcr.io/modular/magic:latest
```

There are different tags for different base images available:
Expand All @@ -23,22 +23,22 @@ There are different tags for different base images available:

## Usage with shell-hook

The following example uses the pixi docker image as a base image for a multi-stage build.
It also makes use of the `shell-hook` feature of pixi to define a convenient entry point (after executing the `shell-hook` script, the environment is activated.
The following example uses the magic docker image as a base image for a multi-stage build.
It also makes use of the `shell-hook` feature of magic to define a convenient entry point (after executing the `shell-hook` script, the environment is activated.

```Dockerfile
FROM ghcr.io/prefix-dev/pixi:0.18.0 AS build
FROM ghcr.io/prefix-dev/magic:latest AS build

# copy source code, pixi.toml and pixi.lock to the container
# copy source code, pixi.toml and magic.lock to the container
COPY . /app
WORKDIR /app
# run some compilation / build task (if needed)
RUN pixi run build
# run the `install` command (or any other). This will also install the dependencies into `/app/.pixi`
RUN magic run build
# run the `install` command (or any other). This will also install the dependencies into `/app/.magic`
# assumes that you have a `prod` environment defined in your pixi.toml
RUN pixi run install -e prod
RUN magic run install -e prod
# Create the shell-hook bash script to activate the environment
RUN pixi shell-hook -e prod > /shell-hook.sh
RUN magic shell-hook -e prod > /shell-hook.sh

# extend the shell-hook script to run the command passed to the container
RUN echo 'exec "$@"' >> /shell-hook.sh
Expand All @@ -47,13 +47,13 @@ FROM ubuntu:22.04 AS production

# only copy the production environment into prod container
# please note that the "prefix" (path) needs to stay the same as in the build container
COPY --from=build /app/.pixi/envs/prod /app/.pixi/envs/prod
COPY --from=build /app/.magic/envs/prod /app/.magic/envs/prod
COPY --from=build /shell-hook.sh /shell-hook.sh
WORKDIR /app
EXPOSE 8000

# set the entrypoint to the shell-hook script (activate the environment and run the command)
# no more pixi needed in the prod container
# no more magic needed in the prod container
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]

CMD ["start-server"]
Expand Down
2 changes: 1 addition & 1 deletion example/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.pixi/
.magic/
2 changes: 1 addition & 1 deletion example/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML
magic.lock linguist-language=YAML
4 changes: 2 additions & 2 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pixi environments
.pixi
# magic environments
.magic

__pycache__/
*.pyc
12 changes: 6 additions & 6 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM ghcr.io/prefix-dev/pixi:0.18.0 AS build
FROM ghcr.io/modular/magic:0.4.0 AS build

# copy source code, pixi.toml and pixi.lock to the container
COPY . /app
WORKDIR /app

# run some compilation / build task (if needed)
RUN pixi run build-wheel
RUN pixi run postinstall-production
RUN magic run build-wheel
RUN magic run postinstall-production

# Create the shell-hook bash script to activate the environment
RUN pixi shell-hook -e prod > /shell-hook.sh
RUN magic shell-hook -e prod > /shell-hook.sh

# extend the shell-hook script to run the command passed to the container
RUN echo 'exec "$@"' >> /shell-hook.sh
Expand All @@ -18,13 +18,13 @@ FROM ubuntu:22.04 AS production

# only copy the production environment into prod container
# please note that the "prefix" (path) needs to stay the same as in the build container
COPY --from=build /app/.pixi/envs/prod /app/.pixi/envs/prod
COPY --from=build /app/.magic/envs/prod /app/.magic/envs/prod
COPY --from=build /shell-hook.sh /shell-hook.sh
WORKDIR /app
EXPOSE 8000

# set the entrypoint to the shell-hook script (activate the environment and run the command)
# no more pixi needed in the prod container
# no more magic needed in the prod container
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]

CMD ["gunicorn", "-w", "4", "docker_project:app", "--bind", ":8000"]
6 changes: 3 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This example is using docker in combination with [solve-groups](https://pixi.sh/
The solve-groups ensure that the `default` environment (where the tests are run) is using *exactly* the same versions of the dependencies as the `prod` environment.

In the docker container, we only copy the `prod` environment into the final layer, so the `default` environment and all its dependencies are not included in the final image.
Also, `pixi` itself is not included in the final image and we activate the environment using `pixi -e prod shell-hook`.
Also, `magic` itself is not included in the final image and we activate the environment using `magic -e prod shell-hook`.

## Usage

To build and run the docker container you require [`docker`](https://docs.docker.com/engine/install/)
When you have `docker` use the following commands:

```shell
docker build -t pixi-docker .
docker run -p 8000:8000 pixi-docker
docker build -t magic-docker .
docker run -p 8000:8000 magic-docker
```
Loading

0 comments on commit eab5103

Please sign in to comment.