Skip to content

Commit 79ab8f8

Browse files
committed
feat: Build inside docker
1 parent a576e6e commit 79ab8f8

6 files changed

Lines changed: 142 additions & 1 deletion

File tree

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
},
66
"files.associations": {
77
"*.sh.in": "gotmpl"
8-
}
8+
},
9+
"hadolint.cliOptions": [
10+
"--no-color",
11+
"--config",
12+
"./alteriso/.hadolint.yaml"
13+
],
914
}

alteriso/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
work
2+
out

alteriso/.hadolint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignored:
2+
- DL3007
3+
- DL3018

alteriso/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM archlinux:latest AS arch
2+
3+
# Update system and install archiso
4+
RUN pacman -Syu --noconfirm && \
5+
pacman -Scc --noconfirm
6+
7+
8+
FROM arch AS archiso
9+
10+
# Install archiso
11+
RUN pacman -S --noconfirm archiso jq && \
12+
pacman -Scc --noconfirm
13+
14+
FROM arch AS golang-dev
15+
16+
RUN pacman -S --noconfirm git go jq base-devel && \
17+
pacman -Scc --noconfirm
18+
19+
FROM golang-dev AS builder
20+
WORKDIR /build
21+
COPY . .
22+
23+
# Build the binary with optimization flags
24+
RUN CGO_ENABLED=0 GOOS=linux go build \
25+
-ldflags="-s -w" \
26+
-trimpath \
27+
-o alteriso ./src
28+
29+
# Final stage
30+
FROM archiso AS alteriso
31+
32+
COPY --from=builder /build/alteriso /usr/local/bin/alteriso
33+
COPY ./configs /usr/share/alteriso/configs
34+
COPY ./modules /usr/share/alteriso/modules
35+
COPY ./bootloaders /usr/share/alteriso/bootloaders
36+
RUN chmod +x /usr/local/bin/alteriso
37+
38+
39+
# FROM alteriso
40+
41+
# WORKDIR /app
42+
# RUN --security=insecure <<EOF
43+
# alteriso profile \
44+
# --bootloaders /usr/share/alteriso/bootloaders \
45+
# --modules /usr/share/alteriso/modules \
46+
# generate \
47+
# -o ./out /usr/share/alteriso/configs/xfce
48+
# mkarchiso -v -o ./out -w ./work ./out/xfce
49+
# EOF
50+
51+
52+
53+

alteriso/compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
alteriso:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
privileged: true
7+
working_dir: /app
8+
volumes:
9+
- ./out:/app/out
10+
# - ./work:/app/work
11+
command: alteriso profile build /usr/share/alteriso/configs/xfce
12+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package profile
2+
3+
import (
4+
"fmt"
5+
"log/slog"
6+
"os"
7+
"path"
8+
9+
"github.com/FascodeNet/alterlinux/src/internal/archiso"
10+
"github.com/FascodeNet/alterlinux/src/internal/errors"
11+
"github.com/Hayao0819/nahi/exutils"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
func buildCmd() *cobra.Command {
16+
outDir := "./out"
17+
cmd := cobra.Command{
18+
Use: "build",
19+
Short: "Build the ISO from generated profile",
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
configDir := args[0]
22+
configName := path.Base(configDir)
23+
24+
bootloadersPath := cmd.Parent().PersistentFlags().Lookup("bootloaders").Value.String()
25+
modulesPath := cmd.Parent().PersistentFlags().Lookup("modules").Value.String()
26+
27+
profile, err := archiso.NewProfile(configDir, bootloadersPath, modulesPath)
28+
if err != nil {
29+
return err
30+
}
31+
32+
profileDir, err := os.MkdirTemp("", fmt.Sprintf("alteriso-%s-*", configName))
33+
if err != nil {
34+
return errors.Wrap(err)
35+
}
36+
defer os.RemoveAll(profileDir)
37+
38+
if err := profile.GenArchisoProfile(profileDir); err != nil {
39+
return errors.Wrap(err)
40+
}
41+
42+
slog.Info("Generated archiso profile", "dir", profileDir)
43+
44+
mkarchiso, err := archiso.MkarchisoPath()
45+
if err != nil {
46+
return errors.Wrap(err)
47+
}
48+
49+
if err := exutils.CommandWithStdio(mkarchiso, "-v", "-w", "work", "-o", outDir, profileDir).Run(); err != nil {
50+
return errors.Wrap(err)
51+
}
52+
53+
return nil
54+
55+
},
56+
}
57+
58+
cmd.Flags().StringVarP(&outDir, "out", "o", outDir, "Output directory")
59+
60+
return &cmd
61+
62+
}
63+
64+
func init() {
65+
profileReg.Add(buildCmd())
66+
}

0 commit comments

Comments
 (0)