Skip to content

Commit

Permalink
Add targets and rename stack -> base image where appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed Sep 12, 2023
1 parent 64cbf95 commit 37ce19a
Show file tree
Hide file tree
Showing 51 changed files with 550 additions and 398 deletions.
110 changes: 55 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ clean: clean-linux clean-windows
## Linux
####################

build-linux: build-linux-stacks build-linux-packages build-linux-builders build-linux-buildpacks
build-linux: build-linux-bases build-linux-packages build-linux-builders build-linux-buildpacks

build-linux-stacks: build-stack-alpine build-stack-jammy
build-linux-bases: build-base-alpine build-base-jammy

build-alpine: build-stack-alpine build-builder-alpine build-buildpacks-alpine
build-alpine: build-base-alpine build-builder-alpine build-buildpacks-alpine

build-jammy: build-stack-jammy build-builder-jammy build-buildpacks-jammy
build-jammy: build-base-jammy build-builder-jammy build-buildpacks-jammy

build-stack-alpine:
@echo "> Building 'alpine' stack..."
bash stacks/build-stack.sh stacks/alpine
build-base-alpine:
@echo "> Building 'alpine' base images..."
bash base-images/build.sh alpine

build-stack-jammy:
@echo "> Building 'jammy' stack..."
bash stacks/build-stack.sh stacks/jammy
build-base-jammy:
@echo "> Building 'jammy' base images..."
bash base-images/build.sh jammy

build-linux-builders: build-builder-alpine build-builder-jammy

Expand Down Expand Up @@ -84,18 +84,18 @@ build-linux-packages: build-sample-root
@echo "> Creating 'hello-universe' buildpack package"
$(PACK_CMD) buildpack package cnbs/sample-package:hello-universe --config $(SAMPLES_ROOT)/packages/hello-universe/package.toml $(PULL_POLICY_NEVER)

deploy-linux: deploy-linux-stacks deploy-linux-packages deploy-linux-builders
deploy-linux: deploy-linux-bases deploy-linux-packages deploy-linux-builders

deploy-linux-stacks:
@echo "> Deploying 'alpine' stack..."
docker push cnbs/sample-stack-base:alpine
docker push cnbs/sample-stack-run:alpine
docker push cnbs/sample-stack-build:alpine
deploy-linux-bases:
@echo "> Deploying 'alpine' base images..."
docker push cnbs/sample-base:alpine
docker push cnbs/sample-base-run:alpine
docker push cnbs/sample-base-build:alpine

@echo "> Deploying 'jammy' stack..."
docker push cnbs/sample-stack-base:jammy
docker push cnbs/sample-stack-run:jammy
docker push cnbs/sample-stack-build:jammy
@echo "> Deploying 'jammy' base images..."
docker push cnbs/sample-base:jammy
docker push cnbs/sample-base-run:jammy
docker push cnbs/sample-base-build:jammy

deploy-linux-packages:
@echo "> Deploying linux packages..."
Expand All @@ -111,15 +111,15 @@ deploy-linux-builders:
docker push cnbs/sample-builder:jammy

clean-linux:
@echo "> Removing 'alpine' stack..."
docker rmi cnbs/sample-stack-base:alpine || true
docker rmi cnbs/sample-stack-run:alpine || true
docker rmi cnbs/sample-stack-build:alpine || true
@echo "> Removing 'alpine' base images..."
docker rmi cnbs/sample-base:alpine || true
docker rmi cnbs/sample-base-run:alpine || true
docker rmi cnbs/sample-base-build:alpine || true

@echo "> Removing 'jammy' stack..."
docker rmi cnbs/sample-stack-base:jammy || true
docker rmi cnbs/sample-stack-run:jammy || true
docker rmi cnbs/sample-stack-build:jammy || true
@echo "> Removing 'jammy' base images..."
docker rmi cnbs/sample-base:jammy || true
docker rmi cnbs/sample-base-run:jammy || true
docker rmi cnbs/sample-base-build:jammy || true

@echo "> Removing builders..."
docker rmi cnbs/sample-builder:alpine || true
Expand Down Expand Up @@ -157,17 +157,17 @@ set-experimental:

build-windows-2022: build-windows-packages build-dotnet-framework-2022

build-nanoserver-2022: build-stack-nanoserver-2022 build-builder-nanoserver-2022 build-buildpacks-nanoserver-2022
build-nanoserver-2022: build-base-nanoserver-2022 build-builder-nanoserver-2022 build-buildpacks-nanoserver-2022

build-dotnet-framework-2022: build-stack-dotnet-framework-2022 build-builder-dotnet-framework-2022 build-buildpacks-dotnet-framework-2022
build-dotnet-framework-2022: build-base-dotnet-framework-2022 build-builder-dotnet-framework-2022 build-buildpacks-dotnet-framework-2022

build-stack-nanoserver-2022:
@echo "> Building 'nanoserver-2022' stack..."
bash stacks/build-stack.sh stacks/nanoserver-2022
build-base-nanoserver-2022:
@echo "> Building 'nanoserver-2022' base images..."
bash base-images/build.sh nanoserver-2022

build-stack-dotnet-framework-2022:
@echo "> Building 'dotnet-framework-2022' stack..."
bash stacks/build-stack.sh stacks/dotnet-framework-2022
build-base-dotnet-framework-2022:
@echo "> Building 'dotnet-framework-2022' base images..."
bash base-images/build.sh dotnet-framework-2022

build-builder-nanoserver-2022: build-windows-packages
@echo "> Building 'nanoserver-2022' builder..."
Expand Down Expand Up @@ -200,20 +200,20 @@ deploy-windows-packages:
docker push cnbs/sample-package:hello-world-windows
docker push cnbs/sample-package:hello-universe-windows

deploy-windows-2022: deploy-windows-stacks-2022 deploy-windows-builders-2022
deploy-windows-2022: deploy-windows-bases-2022 deploy-windows-builders-2022

deploy-windows-stacks-2022: deploy-windows-stacks-dotnet-framework-2022 deploy-windows-stacks-nanoserver-2022
deploy-windows-bases-2022: deploy-windows-bases-dotnet-framework-2022 deploy-windows-bases-nanoserver-2022

deploy-windows-stacks-nanoserver-2022:
@echo "> Deploying 'nanoserver-2022' stack..."
docker push cnbs/sample-stack-base:nanoserver-2022
docker push cnbs/sample-stack-run:nanoserver-2022
docker push cnbs/sample-stack-build:nanoserver-2022
deploy-windows-bases-nanoserver-2022:
@echo "> Deploying 'nanoserver-2022' base images..."
docker push cnbs/sample-base:nanoserver-2022
docker push cnbs/sample-base-run:nanoserver-2022
docker push cnbs/sample-base-build:nanoserver-2022

deploy-windows-stacks-dotnet-framework-2022:
@echo "> Deploying 'dotnet-framework-2022' stack..."
docker push cnbs/sample-stack-run:dotnet-framework-2022
docker push cnbs/sample-stack-build:dotnet-framework-2022
deploy-windows-bases-dotnet-framework-2022:
@echo "> Deploying 'dotnet-framework-2022' base images..."
docker push cnbs/sample-base-run:dotnet-framework-2022
docker push cnbs/sample-base-build:dotnet-framework-2022

deploy-windows-builders-2022: deploy-windows-builders-dotnet-framework-2022 deploy-windows-builders-nanoserver-2022

Expand All @@ -226,14 +226,14 @@ deploy-windows-builders-dotnet-framework-2022:
docker push cnbs/sample-builder:dotnet-framework-2022

clean-windows:
@echo "> Removing 'nanoserver-2022' stack..."
docker rmi cnbs/sample-stack-base:nanoserver-2022 || true
docker rmi cnbs/sample-stack-run:nanoserver-2022 || true
docker rmi cnbs/sample-stack-build:nanoserver-2022 || true

@echo "> Removing 'dotnet-framework-2022' stack..."
docker rmi cnbs/sample-stack-run:dotnet-framework-2022 || true
docker rmi cnbs/sample-stack-build:dotnet-framework-2022 || true
@echo "> Removing 'nanoserver-2022' base images..."
docker rmi cnbs/sample-base:nanoserver-2022 || true
docker rmi cnbs/sample-base-run:nanoserver-2022 || true
docker rmi cnbs/sample-base-build:nanoserver-2022 || true

@echo "> Removing 'dotnet-framework-2022' base images..."
docker rmi cnbs/sample-base-run:dotnet-framework-2022 || true
docker rmi cnbs/sample-base-build:dotnet-framework-2022 || true

@echo "> Removing builders..."
docker rmi cnbs/sample-builder:nanoserver-2022 || true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Includes:
- [Apps](apps/)
- [Buildpacks](buildpacks/)
- [Builders](builders/)
- [Stacks](stacks/)
- [Base Images](base-images/)
- [Packages](packages/)


Expand Down
10 changes: 2 additions & 8 deletions apps/bash-script/bash-script-buildpack/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ id = "samples/bash-script"
version = "0.0.1"
name = "Bash Script Buildpack"

# Stacks that the buildpack will work with
# Stacks (deprecated) the buildpack will work with
[[stacks]]
id = "io.buildpacks.samples.stacks.jammy"

[[stacks]]
id = "io.buildpacks.samples.stacks.alpine"

[[stacks]]
id = "io.buildpacks.stacks.jammy"
id = "*"
8 changes: 7 additions & 1 deletion apps/batch-script/batch-script-buildpack/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ id = "samples/batch-script"
version = "0.0.1"
name = "Batch Script Buildpack"

# Stacks that the buildpack will work with
# Targets the buildpack will work with
[[targets]]
os = "windows"
[[targets.distros]]
version = "10.0.20348.1906"

# Stacks (deprecated) the buildpack will work with
[[stacks]]
id = "io.buildpacks.samples.stacks.nanoserver-2022"
2 changes: 1 addition & 1 deletion stacks/README.md → base-images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To build the stack use the `./build-stack` script:
```text
Usage:
./stacks/build-stack.sh [-f <prefix>] [-p <platform>] <dir>
-f prefix to use for images (default: cnbs/sample-stack)
-f prefix to use for images (default: cnbs/sample-base)
-p prefix to use for images (default: amd64)
<dir> directory of stack to build
```
Expand Down
23 changes: 23 additions & 0 deletions base-images/alpine/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM --platform=linux/amd64 alpine:3

# Install packages that we want to make available at both build and run time
RUN apk add --update --no-cache bash ca-certificates

# Create user and group
ARG cnb_uid=1000
ARG cnb_gid=1001
RUN addgroup -g ${cnb_gid} cnb && \
adduser -u ${cnb_uid} -G cnb -s /bin/bash -D cnb

# Set user and group
USER ${cnb_uid}:${cnb_gid}

# Set required CNB target information
ARG distro_name
LABEL io.buildpacks.base.distro.name=${distro_name}
ARG distro_version
LABEL io.buildpacks.base.distro.version=${distro_version}

# Set deprecated CNB stack information (see https://buildpacks.io/docs/reference/spec/migration/platform-api-0.11-0.12/#stacks-are-deprecated-1)
ARG stack_id
LABEL io.buildpacks.stack.id="${stack_id}"
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ RUN apk add --update ca-certificates git jq wget && \

COPY ./bin/yj-linux /usr/local/bin/yj

# Set required CNB information
# Set required CNB user information
ENV CNB_USER_ID=${cnb_uid}
ENV CNB_GROUP_ID=${cnb_gid}

# Set deprecated CNB stack information (see https://buildpacks.io/docs/reference/spec/migration/platform-api-0.11-0.12/#stacks-are-deprecated-1)
ARG stack_id
ENV CNB_STACK_ID=${stack_id}
LABEL io.buildpacks.stack.id=${stack_id}

# Set user and group (as declared in base image)
USER ${CNB_USER_ID}:${CNB_GROUP_ID}
File renamed without changes.
2 changes: 2 additions & 0 deletions base-images/alpine/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ARG base_image
FROM ${base_image}
22 changes: 22 additions & 0 deletions base-images/alpine/run/curl.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM curlimages/curl

COPY ./Dockerfile /home/curl_user/Dockerfile

RUN curl --version

# Create user and group
ARG cnb_uid=1000
ARG cnb_gid=1001
USER root
RUN addgroup -g ${cnb_gid} cnb && \
adduser -u ${cnb_uid} -G cnb -s /bin/bash -D cnb

# Set user and group
USER ${cnb_uid}:${cnb_gid}

# Set required CNB target information
LABEL io.buildpacks.base.distro.name=alpine
LABEL io.buildpacks.base.distro.version=3.18.2

# Set deprecated CNB stack information (see https://buildpacks.io/docs/reference/spec/migration/platform-api-0.11-0.12/#stacks-are-deprecated-1)
LABEL io.buildpacks.stack.id=io.buildpacks.samples.stacks.alpine
102 changes: 102 additions & 0 deletions base-images/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
set -e

ID_PREFIX="io.buildpacks.samples.stacks"

DEFAULT_PREFIX=cnbs/sample-base
DEFAULT_PLATFORM=amd64

REPO_PREFIX=${DEFAULT_PREFIX}
PLATFORM=${DEFAULT_PLATFORM}

usage() {
echo "Usage: "
echo " $0 [-f <prefix>] [-p <platform>] <dir>"
echo " -f prefix to use for images (default: ${DEFAULT_PREFIX})"
echo " -p prefix to use for images (default: ${DEFAULT_PLATFORM})"
echo " <dir> directory to build"
exit 1;
}

while getopts "v:p:" o; do
case "${o}" in
f)
REPO_PREFIX=${OPTARG}
;;
p)
PLATFORM=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG" 1>&2
usage
;;
:)
usage
;;
esac
done

BASE_DIR=${@:$OPTIND:1}

if [[ -z ${REPO_PREFIX} ]]; then
echo "Prefix cannot be empty"
echo
usage
exit 1
fi

if [[ -z ${BASE_DIR} ]]; then
echo "Must specify directory"
echo
usage
exit 1
fi

cd $(dirname $0)

IMAGE_DIR=$(realpath "${BASE_DIR}")
TAG=$(basename "${IMAGE_DIR}")
STACK_ID="${ID_PREFIX}.$(basename "${IMAGE_DIR}")"
BASE_IMAGE=${REPO_PREFIX}:${TAG}
RUN_IMAGE=${REPO_PREFIX}-run:${TAG}
BUILD_IMAGE=${REPO_PREFIX}-build:${TAG}

if [[ -d "${IMAGE_DIR}/base" ]]; then
docker build --platform=${PLATFORM} \
--build-arg "distro_name=${DISTRO_NAME}" \
--build-arg "distro_version=${DISTRO_VERSION}" \
--build-arg "stack_id=${STACK_ID}" \
-t "${BASE_IMAGE}" \
"${IMAGE_DIR}/base"
fi

# Get target distro information
if cmd /c ver; then
DISTRO_NAME=""
DISTRO_VERSION=$(docker run --rm --entrypoint bash "${BASE_IMAGE}" cmd /c ver | sed 's/Microsoft Windows //' | sed 's/[][]//g' | cut -d' ' -f2)
else
DISTRO_NAME=$(docker run --rm "${BASE_IMAGE}" cat /etc/os-release | grep '^ID=' | cut -d'=' -f2)
DISTRO_VERSION=$(docker run --rm "${BASE_IMAGE}" cat /etc/os-release | grep '^VERSION_ID=' | cut -d'=' -f2)
fi

echo "BUILDING ${BUILD_IMAGE}..."
docker build --platform=${PLATFORM} \
--build-arg "base_image=${BASE_IMAGE}" \
--build-arg "stack_id=${STACK_ID}" \
-t "${BUILD_IMAGE}" \
"${IMAGE_DIR}/build"

echo "BUILDING ${RUN_IMAGE}..."
docker build --platform=${PLATFORM} \
--build-arg "base_image=${BASE_IMAGE}" \
--build-arg "stack_id=${STACK_ID}" \
-t "${RUN_IMAGE}" \
"${IMAGE_DIR}/run"

echo
echo "BASE IMAGES BUILT!"
echo
echo "Images:"
for IMAGE in "${BASE_IMAGE}" "${BUILD_IMAGE}" "${RUN_IMAGE}"; do
echo " ${IMAGE}"
done
14 changes: 14 additions & 0 deletions base-images/dotnet-framework-2022/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022

# Set user
USER ContainerAdministrator

# Set required CNB target information
ARG distro_name
LABEL io.buildpacks.base.distro.name=${distro_name}
ARG distro_version
LABEL io.buildpacks.base.distro.version=${distro_version}

# Set deprecated CNB stack information (see https://buildpacks.io/docs/reference/spec/migration/platform-api-0.11-0.12/#stacks-are-deprecated-1)
ARG stack_id
LABEL io.buildpacks.stack.id=${stack_id}
Loading

0 comments on commit 37ce19a

Please sign in to comment.