Sign inSign up

digi4care/zig-compiler

By digi4care

•Updated over 1 year ago

Docker images for building and running Zig applications (Alpine and BusyBox variants).

Image
Languages & frameworks
Developer tools
1

450

digi4care/zig-compiler repository overview

⁠Zig Docker Setup

This repository contains Dockerfiles and commands to create a Zig development environment and application containers. Different image options are provided for various use-cases, from development to production.

⁠Docker Images

⁠1. Zig Compiler Image

This image includes Zig and necessary development tools such as curl, jq, xz, git, make, musl-dev, gdb, g++, and llvm.

⁠2. Alpine Dockerfile (For dynamically linked executables)
# STAGE 1: Build the application using the existing zig-development image
FROM digi4care/zig-compiler:latest AS builder

# Zet de werkdirectory in de container
WORKDIR /app

# Kopieer de Zig broncode naar de container
COPY app/src/ ./src/

# Compileer de Zig applicatie
RUN zig build-exe src/main.zig

# STAGE 2: Create a minimal production image
FROM alpine:latest AS production

# Installeer CA-certificaten (voor HTTPS-verbindingen, indien nodig)
RUN apk --no-cache add ca-certificates

# Zet de werkdirectory
WORKDIR /app

# Kopieer het gecompileerde binaire bestand van de builder stage
COPY --from=builder /app/main .


# Stel het entrypoint in voor de container
ENTRYPOINT ["./main"]

This image is suitable for applications that require dynamically linked libraries.

Build the image with the following command:

docker build -t zig-app-alpine -f Dockerfile.alpine .
⁠3. BusyBox Dockerfile (For statically linked executables)
# STAGE 1: Build the application using the existing zig-development image
FROM digi4care/zig-compiler:latest AS builder

# Zet de werkdirectory in de container
WORKDIR /app

# Kopieer de Zig broncode naar de container
COPY app/src/ ./src/

# Compileer de Zig applicatie
RUN zig build-exe src/main.zig

# STAGE 2: Create a minimal production image
# Only suitable for simple static binaries
FROM busybox:latest AS production

# Zet de werkdirectory
WORKDIR /app

# Kopieer het gecompileerde binaire bestand van de builder stage
COPY --from=builder /app/main .


# Stel het entrypoint in voor de container
ENTRYPOINT ["./main"]


This image is optimized for statically linked executables, which do not require external libraries.

Build the image with the following command:

docker build -t zig-app -f Dockerfile.busybox .

⁠Commands

⁠1. Creating a New Zig Project

To initialize a new Zig project in the app directory, run the following command:

docker run --rm -v "$(pwd)/app:/app" -w /app digi4care/zig-compiler:latest zig init
⁠2. Compiling a Zig Program

To compile a Zig program with the release-fast option, run the following command:

docker run --rm -v "$(pwd)/app:/app" -w /app digi4care/zig-compiler:latest zig build-exe src/main.zig -Drelease-fast
⁠3. Running a Zig Program

To run the compiled Zig program, use one of the following commands based on the chosen image:

⁠Alpine Image
docker run --rm -it zig-app-alpine:latest
⁠BusyBox Image
docker run --rm -it zig-app-busybox:latest

⁠Notes

  • Make sure to use the appropriate image for your use case: Alpine for dynamically linked executables, BusyBox for statically linked executables.
  • The commands use the -v flag to mount the local directory into the container and the -w flag to set the working directory inside the container.

Tag summary

Content type

Image

Digest

sha256:d7e251a66…

Size

188.1 MB

Last updated

over 1 year ago

docker pull digi4care/zig-compiler