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

Create a fork for magic #1

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @pavelzw
* @modular/magic
200 changes: 100 additions & 100 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 All @@ -39,112 +39,112 @@ jobs:
fail-fast: false
matrix:
base-image:
- debian:bookworm-slim # 12
- debian:bookworm # 12
- debian:bullseye-slim # 11
- debian:bullseye # 11
- ubuntu:noble # 24.04
- ubuntu:mantic # 23.10
- ubuntu:jammy # 22.04
- ubuntu:focal # 20.04
- nvidia/cuda:12.3.1-base-ubuntu22.04
- nvidia/cuda:12.3.1-base-ubuntu20.04
- nvidia/cuda:12.2.2-base-ubuntu22.04
- nvidia/cuda:12.2.2-base-ubuntu20.04
- nvidia/cuda:12.1.1-base-ubuntu22.04
- nvidia/cuda:12.1.1-base-ubuntu20.04
- nvidia/cuda:11.8.0-base-ubuntu22.04
- nvidia/cuda:11.8.0-base-ubuntu20.04
- nvidia/cuda:11.7.1-base-ubuntu22.04
- nvidia/cuda:11.7.1-base-ubuntu20.04
- nvidia/cuda:11.6.2-base-ubuntu20.04
- nvidia/cuda:11.4.3-base-ubuntu20.04
- nvidia/cuda:11.3.1-base-ubuntu20.04
- nvidia/cuda:11.2.2-base-ubuntu20.04
- debian:bookworm-slim # 12
- debian:bookworm # 12
- debian:bullseye-slim # 11
- debian:bullseye # 11
- ubuntu:noble # 24.04
- ubuntu:mantic # 23.10
- ubuntu:jammy # 22.04
- ubuntu:focal # 20.04
- nvidia/cuda:12.3.1-base-ubuntu22.04
- nvidia/cuda:12.3.1-base-ubuntu20.04
- nvidia/cuda:12.2.2-base-ubuntu22.04
- nvidia/cuda:12.2.2-base-ubuntu20.04
- nvidia/cuda:12.1.1-base-ubuntu22.04
- nvidia/cuda:12.1.1-base-ubuntu20.04
- nvidia/cuda:11.8.0-base-ubuntu22.04
- nvidia/cuda:11.8.0-base-ubuntu20.04
- nvidia/cuda:11.7.1-base-ubuntu22.04
- nvidia/cuda:11.7.1-base-ubuntu20.04
- nvidia/cuda:11.6.2-base-ubuntu20.04
- nvidia/cuda:11.4.3-base-ubuntu20.04
- nvidia/cuda:11.3.1-base-ubuntu20.04
- nvidia/cuda:11.2.2-base-ubuntu20.04
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set image variables
id: image-variables
env:
IMAGE: ${{ matrix.base-image }}
run: |
import os
- name: Checkout source
uses: actions/checkout@v4
- name: Set image variables
id: image-variables
env:
IMAGE: ${{ matrix.base-image }}
run: |
import os

base_image = "${{ matrix.base-image }}"
if base_image.startswith("nvidia/cuda"):
code_names = {
"22.04": "jammy",
"20.04": "focal",
"23.10": "mantic",
"24.04": "noble",
}
ubuntu_version_number = base_image.split("-ubuntu")[-1]
base_tag = base_image.split(":")[-1]
cuda_version = base_tag.split("-")[0]
tag = f"{code_names[ubuntu_version_number]}-cuda-{cuda_version}"
platforms = "linux/amd64,linux/arm64"
else:
tag = base_image.split(":")[-1]
platforms = "linux/amd64,linux/arm64"
is_default = "true" if base_image == "${{ env.DEFAULT_BASE_IMAGE }}" else "false"
base_image = "${{ matrix.base-image }}"
if base_image.startswith("nvidia/cuda"):
code_names = {
"22.04": "jammy",
"20.04": "focal",
"23.10": "mantic",
"24.04": "noble",
}
ubuntu_version_number = base_image.split("-ubuntu")[-1]
base_tag = base_image.split(":")[-1]
cuda_version = base_tag.split("-")[0]
tag = f"{code_names[ubuntu_version_number]}-cuda-{cuda_version}"
platforms = "linux/amd64,linux/arm64"
else:
tag = base_image.split(":")[-1]
platforms = "linux/amd64,linux/arm64"
is_default = "true" if base_image == "${{ env.DEFAULT_BASE_IMAGE }}" else "false"

GITHUB_OUTPUT = os.environ["GITHUB_OUTPUT"]
with open(GITHUB_OUTPUT, "a") as f:
f.write(f"tag={tag}\n")
f.write(f"platforms={platforms}\n")
f.write(f"is-default={is_default}\n")
shell: python
- name: Get docker metadata
id: metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |-
ghcr.io/prefix-dev/pixi
flavor: latest=false
# latest
# base-image
# major.minor.patch
# major.minor.patch-base-image
tags: |
GITHUB_OUTPUT = os.environ["GITHUB_OUTPUT"]
with open(GITHUB_OUTPUT, "a") as f:
f.write(f"tag={tag}\n")
f.write(f"platforms={platforms}\n")
f.write(f"is-default={is_default}\n")
shell: python
- name: Get docker metadata
id: metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |-
ghcr.io/modular/magic
flavor: latest=false
# latest
# base-image
# major.minor.patch
# major.minor.patch-base-image
tags: |
type=raw,value=latest,priority=1000,enable=${{ steps.image-variables.outputs.is-default }}
type=raw,value=${{ steps.image-variables.outputs.tag }},priority=900
type=semver,pattern={{version}},enable=${{ steps.image-variables.outputs.is-default }},value=${{ needs.version.outputs.new-version }},priority=800
type=semver,pattern={{version}}-${{ steps.image-variables.outputs.tag }},value=${{ needs.version.outputs.new-version }},priority=500
- name: Setup docker buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349
- name: Login to GHCR
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker images
id: build
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
with:
# provenance: false is needed to avoid unkown/unknown os/arch on ghcr
# see: https://github.com/docker/build-push-action/issues/820
provenance: false
platforms: ${{ steps.image-variables.outputs.platforms }}
push: ${{ needs.version.outputs.push == 'true' }}
build-args: |-
BASE_IMAGE=${{ matrix.base-image }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.image-variables.outputs.tag }}
path: ${{ steps.metadata.outputs.bake-file }}
- name: Run tests
# buildx does not support outputting the image so we need to pull it and run tests
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"
- name: Image digest
run: echo ${{ steps.build.outputs.digest }}
- name: Setup docker buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349
- name: Login to GHCR
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker images
id: build
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
with:
# provenance: false is needed to avoid unkown/unknown os/arch on ghcr
# see: https://github.com/docker/build-push-action/issues/820
provenance: false
platforms: ${{ steps.image-variables.outputs.platforms }}
push: ${{ needs.version.outputs.push == 'true' }}
build-args: |-
BASE_IMAGE=${{ matrix.base-image }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.image-variables.outputs.tag }}
path: ${{ steps.metadata.outputs.bake-file }}
- name: Run tests
# buildx does not support outputting the image so we need to pull it and run tests
if: needs.version.outputs.push == 'true'
run: |
docker images
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 }}

release:
needs: [version, build]
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
Loading
Loading