Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: 26974fb7298852354f32134fa7ab321a8d7e49b6
Timestamp: Fri, 12 Apr 2024 18:42:07 +0000 (8 months ago)

+199 -5 +/-10 browse
add initial support for running ayllu via podman
add initial support for running ayllu via podman

This adds the basic tooling to support container based workflows with Podman.
It only adds the ability to run the basic ayllu/quipu components without
support for mail, chat, etc. those components will come after.
1diff --git a/.containerignore b/.containerignore
2new file mode 100644
3index 0000000..eb5a316
4--- /dev/null
5+++ b/.containerignore
6 @@ -0,0 +1 @@
7+ target
8 diff --git a/ayllu/src/config.rs b/ayllu/src/config.rs
9index 9d400b0..da52ef2 100644
10--- a/ayllu/src/config.rs
11+++ b/ayllu/src/config.rs
12 @@ -67,7 +67,7 @@ pub struct Web {
13
14 impl Web {
15 fn default_themes_path() -> String {
16- String::from("themes")
17+ String::from("/usr/lib/ayllu/themes")
18 }
19
20 fn default_base_theme() -> String {
21 diff --git a/containers/base/Containerfile b/containers/base/Containerfile
22new file mode 100644
23index 0000000..5bd0f9f
24--- /dev/null
25+++ b/containers/base/Containerfile
26 @@ -0,0 +1,52 @@
27+ FROM alpine:3.19.1 AS build
28+
29+ RUN apk add \
30+ cargo rust pkgconf sqlite sassc npm \
31+ openssl openssl-dev fontconfig fontconfig-dev
32+ RUN adduser -D -s /bin/sh -h /home/builder builder
33+
34+ USER builder
35+
36+ ENV PATH="/home/builder/.cargo/bin:$PATH"
37+ RUN cargo install --color=never --no-default-features --features sqlite sqlx-cli
38+
39+ USER root
40+ COPY . /home/builder/src
41+ WORKDIR /home/builder/src
42+ RUN chown -R builder /home/builder/src
43+
44+ USER builder
45+
46+ RUN cargo fetch --color=never --locked
47+ RUN scripts/check_build_dependencies.sh || true
48+ RUN scripts/ensure_database.sh ayllu
49+
50+ # build the main Ayllu binary
51+ RUN cargo build \
52+ --color=never --locked --frozen --offline --release --package ayllu
53+
54+ # build the Quipu binary
55+ RUN cargo build \
56+ --color=never --locked --frozen --offline --release --package quipu
57+
58+ RUN npm install && scripts/compile_stylesheets.sh
59+
60+ FROM alpine:3.19.1
61+
62+ RUN apk add \
63+ fontconfig libgit2-dev sqlite \
64+ tree-sitter-grammars # all of the syntax highlighting available in alpine
65+
66+ COPY --from=build --chown=0:0 /home/builder/src/target/release/ayllu /usr/bin/
67+ COPY --from=build --chown=0:0 /home/builder/src/target/release/quipu /usr/bin/
68+ COPY --from=build --chown=0:0 /home/builder/src/ayllu/themes /usr/lib/ayllu/themes
69+
70+ RUN adduser -D -s /bin/sh -h /home/ayllu ayllu
71+
72+ # generate a default server config to fallback to
73+ RUN mkdir -p /etc/ayllu && ayllu config generate > /etc/ayllu/config.yaml
74+
75+ USER ayllu
76+ WORKDIR /home/ayllu
77+
78+ CMD ["/usr/bin/ayllu", "serve"]
79 diff --git a/containers/base/README.md b/containers/base/README.md
80new file mode 100644
81index 0000000..d7930dc
82--- /dev/null
83+++ b/containers/base/README.md
84 @@ -0,0 +1,4 @@
85+ # Base Container Configuration
86+
87+ This container has all of the software required to run a basic installation of
88+ Ayllu without any server extensions such as mail, builds, etc.
89 diff --git a/contrib/systemd-podman/ayllu.container b/contrib/systemd-podman/ayllu.container
90new file mode 100644
91index 0000000..0aa5e32
92--- /dev/null
93+++ b/contrib/systemd-podman/ayllu.container
94 @@ -0,0 +1,37 @@
95+ [Unit]
96+ Description=Ayllu container
97+
98+ # Specify the dependencies
99+ Wants=network-online.target
100+ After=network-online.target nss-lookup.target
101+
102+ [Container]
103+ ContainerName=ayllu
104+ Image=registry.ayllu-forge.org/projects/ayllu:main
105+
106+ # Enable auto-update container
107+ # AutoUpdate=registry
108+
109+ Volume=/etc/ayllu:/etc/ayllu
110+ # Volume=/path/to/data1:/data1
111+
112+ HostName=ayllu
113+ PublishPort=127.0.0.1:8080:8080/tcp
114+
115+ Environment=PUID=1000
116+ Environment=PGID=1000
117+ Environment=TZ=Etc/UTC
118+
119+ UIDMap=1000:0:1
120+ UIDMap=0:1:1000
121+ UIDMap=1001:1001:64536
122+
123+ [Service]
124+ Restart=on-failure
125+
126+ # Extend Timeout to allow time to pull the image
127+ TimeoutStartSec=300
128+
129+ # The [Install] section allows enabling the generated service.
130+ [Install]
131+ WantedBy=default.target
132 diff --git a/scripts/build_container.sh b/scripts/build_container.sh
133new file mode 100755
134index 0000000..e5f2be5
135--- /dev/null
136+++ b/scripts/build_container.sh
137 @@ -0,0 +1,15 @@
138+ #!/bin/sh
139+ set -e
140+
141+ REGISTRY="registry-auth.ayllu-forge.org"
142+ IMAGE_NAME="projects/ayllu"
143+ COMMIT_ID="$(git rev-parse HEAD)"
144+ BRANCH_NAME="$(git branch --show-current)"
145+
146+ podman \
147+ build --network=host \
148+ -t "$REGISTRY/$IMAGE_NAME:$COMMIT_ID" \
149+ -f containers/base/Containerfile .
150+
151+ podman tag \
152+ "$REGISTRY/$IMAGE_NAME:$COMMIT_ID" "$REGISTRY/$IMAGE_NAME:$BRANCH_NAME"
153 diff --git a/scripts/ensure_database.sh b/scripts/ensure_database.sh
154index 8e344f6..f1a897c 100755
155--- a/scripts/ensure_database.sh
156+++ b/scripts/ensure_database.sh
157 @@ -1,5 +1,5 @@
158 #!/bin/sh
159- set -e
160+ set -ex
161 # initialize a local database for builds and testing assuming the package
162 # has database support.
163
164 diff --git a/scripts/push_container.sh b/scripts/push_container.sh
165new file mode 100755
166index 0000000..e0f386b
167--- /dev/null
168+++ b/scripts/push_container.sh
169 @@ -0,0 +1,11 @@
170+ #!/bin/sh
171+ set -e
172+
173+ REGISTRY="registry-auth.ayllu-forge.org"
174+ IMAGE_NAME="projects/ayllu"
175+ COMMIT_ID="$(git rev-parse HEAD)"
176+ BRANCH_NAME="$(git branch --show-current)"
177+
178+ podman login "$REGISTRY"
179+ podman push "$REGISTRY/$IMAGE_NAME:$COMMIT_ID"
180+ podman push "$REGISTRY/$IMAGE_NAME:$BRANCH_NAME"
181 diff --git a/www/content/docs/installation.md b/www/content/docs/installation.md
182index 516b28e..8eceebc 100644
183--- a/www/content/docs/installation.md
184+++ b/www/content/docs/installation.md
185 @@ -4,6 +4,65 @@ slug = "installation"
186 weight = 0
187 +++
188
189+ # Running as a Container
190+
191+ The quickest way to get started running Ayllu is by using a container.
192+ [Podman](https://podman.io/) is the only supported container platform although
193+ Docker should work as well.
194+
195+ ### Running as a User
196+
197+ This will run Ayllu from the HEAD of the main branch. Note that the commands
198+ below use a seperate configuration and data paths to avoid conflicting with the
199+ default paths if the Ayllu binary is installed directly on your system.
200+
201+ #### Pull Down The Latest Container Image
202+
203+ mkdir ~/.config/ayllu-podman
204+ podman pull registry.ayllu-forge.org/projects/ayllu:main
205+
206+ #### Create a Configuration File
207+
208+ Add a new collection in your configuration file that points to the directory
209+ you map into the container that has your code within it.
210+
211+ First generate a new configuration file:
212+
213+ podman run --rm -ti registry.ayllu-forge.org/projects/ayllu:main ayllu config generate > ~/.config/ayllu-podman/config.yaml
214+
215+ And then edit the file to point to a new collection path that you will map into
216+ the container in the next step.
217+
218+ ...
219+ [[collections]]
220+ name = "projects"
221+ description = "active projects"
222+ path = "/home/ayllu/repos/projects"
223+ ...
224+
225+ #### Start the container
226+
227+ Now you can start the container ensuring that you map the code collection into
228+ the correct path which you configured in the step above.
229+
230+ podman run -p 8080:8080 -v ~/repos/projects:/home/ayllu/repos/projects \
231+ --rm --ti --name ayllu \
232+ registry.ayllu-forge.org:projects/ayllu:main
233+
234+ You should now be able to browse to the user interface at http://localhost:8080.
235+
236+ Note that no jobs will have been run against any of your repositories so the
237+ charts will not be rendered correctly in the UI. To do this you can exec into
238+ the container and run the jobs manually:
239+
240+ podman exec -ti ayllu sh
241+ cd ~/repos/project/your-repository
242+ ayllu jobs run .
243+
244+ ### Deployment with Systemd
245+
246+ TODO
247+
248 # Distribution Packages
249
250 <div class="warning">
251 @@ -13,10 +72,10 @@ in this regard would be gladly accepted!
252
253 ## Arch Linux
254
255- ###### Release Package
256+ ###### Release Package (Unfinished)
257 [ayllu](https://aur.archlinux.org/packages/ayllu)
258
259- ###### Source Package
260+ ###### Source Package (Unfinished)
261 [ayllu-git](https://aur.archlinux.org/packages/ayllu-git)
262
263
264 diff --git a/www/public/docs/installation/index.html b/www/public/docs/installation/index.html
265index c80ec60..2af3f8c 100644
266--- a/www/public/docs/installation/index.html
267+++ b/www/public/docs/installation/index.html
268 @@ -1 +1,16 @@
269- <!doctype html><html lang=en><head><meta charset=utf-8><link href=/main.css rel=stylesheet><link href=/assets/ayllu_logo.svg rel=icon type=image/svg+xml><link href=/assets/ayllu_logo.png rel=icon sizes=any type=image/png><title>Ayllu</title></head><nav><ul><li><a href=/> <img class=logo src=/assets/ayllu_logo.png> </a></ul><ul><li><a href=https://ayllu-forge.org/browse>browse</a><li><a href=/docs>docs</a></ul></nav><body class=container><div class=wrapper><main class=page-body><div class=documentation><div class=side-panel><ul><li><a href=https://ayllu-forge.org/docs/architecture/>Architecture</a><li><a href=https://ayllu-forge.org/docs/builds/>Builds</a><li><a href=https://ayllu-forge.org/docs/configuration/>Configuration</a><li><a href=https://ayllu-forge.org/docs/developers/>Developers</a><li class=active><a href=https://ayllu-forge.org/docs/installation/>Installation</a><li><a href=https://ayllu-forge.org/docs/faq/>FAQ</a><li><a href=https://ayllu-forge.org/docs/mail/>Mail</a></ul></div><div class=doc-content><h1>Installation</h1><h1 id=distribution-packages><a aria-label="Anchor link for: distribution-packages" class=zola-anchor href=#distribution-packages>Distribution Packages</a></h1><div class=warning>NOTE: Few distribution packages currently exist for Ayllu, any contributions in this regard would be gladly accepted!</div><h2 id=arch-linux><a aria-label="Anchor link for: arch-linux" class=zola-anchor href=#arch-linux>Arch Linux</a></h2><h6 id=release-package><a aria-label="Anchor link for: release-package" class=zola-anchor href=#release-package>Release Package</a></h6><p><a href=https://aur.archlinux.org/packages/ayllu>ayllu</a><h6 id=source-package><a aria-label="Anchor link for: source-package" class=zola-anchor href=#source-package>Source Package</a></h6><p><a href=https://aur.archlinux.org/packages/ayllu-git>ayllu-git</a><h1 id=from-source><a aria-label="Anchor link for: from-source" class=zola-anchor href=#from-source>From Source</a></h1><p>TODO</div></div></main><footer class=page-footer>2024, <a href=/projects/ayllu/blob/main/ATTRIBUTIONS.md>attributions</a></footer></div>
270\ No newline at end of file
271+ <!doctype html><html lang=en><head><meta charset=utf-8><link href=/main.css rel=stylesheet><link href=/assets/ayllu_logo.svg rel=icon type=image/svg+xml><link href=/assets/ayllu_logo.png rel=icon sizes=any type=image/png><title>Ayllu</title></head><nav><ul><li><a href=/> <img class=logo src=/assets/ayllu_logo.png> </a></ul><ul><li><a href=https://ayllu-forge.org/browse>browse</a><li><a href=/docs>docs</a></ul></nav><body class=container><div class=wrapper><main class=page-body><div class=documentation><div class=side-panel><ul><li><a href=https://ayllu-forge.org/docs/architecture/>Architecture</a><li><a href=https://ayllu-forge.org/docs/builds/>Builds</a><li><a href=https://ayllu-forge.org/docs/configuration/>Configuration</a><li><a href=https://ayllu-forge.org/docs/developers/>Developers</a><li class=active><a href=https://ayllu-forge.org/docs/installation/>Installation</a><li><a href=https://ayllu-forge.org/docs/faq/>FAQ</a><li><a href=https://ayllu-forge.org/docs/mail/>Mail</a></ul></div><div class=doc-content><h1>Installation</h1><h1 id=running-as-a-container><a aria-label="Anchor link for: running-as-a-container" class=zola-anchor href=#running-as-a-container>Running as a Container</a></h1><p>The quickest way to get started running Ayllu is by using a container. <a href=https://podman.io/>Podman</a> is the only supported container platform although Docker should work as well.<h3 id=running-as-a-user><a aria-label="Anchor link for: running-as-a-user" class=zola-anchor href=#running-as-a-user>Running as a User</a></h3><p>This will run Ayllu from the HEAD of the main branch. Note that the commands below use a seperate configuration and data paths to avoid conflicting with the default paths if the Ayllu binary is installed directly on your system.<h4 id=pull-down-the-latest-container-image><a aria-label="Anchor link for: pull-down-the-latest-container-image" class=zola-anchor href=#pull-down-the-latest-container-image>Pull Down The Latest Container Image</a></h4><pre><code>mkdir ~/.config/ayllu-podman
272+ podman pull registry.ayllu-forge.org/projects/ayllu:main
273+ </code></pre><h4 id=create-a-configuration-file><a aria-label="Anchor link for: create-a-configuration-file" class=zola-anchor href=#create-a-configuration-file>Create a Configuration File</a></h4><p>Add a new collection in your configuration file that points to the directory you map into the container that has your code within it.<p>First generate a new configuration file:<pre><code>podman run --rm -ti registry.ayllu-forge.org/projects/ayllu:main ayllu config generate > ~/.config/ayllu-podman/config.yaml
274+ </code></pre><p>And then edit the file to point to a new collection path that you will map into the container in the next step.<pre><code>...
275+ [[collections]]
276+ name = "projects"
277+ description = "active projects"
278+ path = "/home/ayllu/repos/projects"
279+ ...
280+ </code></pre><h4 id=start-the-container><a aria-label="Anchor link for: start-the-container" class=zola-anchor href=#start-the-container>Start the container</a></h4><p>Now you can start the container ensuring that you map the code collection into the correct path which you configured in the step above.<pre><code>podman run -p 8080:8080 -v ~/repos/projects:/home/ayllu/repos/projects \
281+ --rm --ti --name ayllu \
282+ registry.ayllu-forge.org:projects/ayllu:main
283+ </code></pre><p>You should now be able to browse to the user interface at http://localhost:8080.<p>Note that no jobs will have been run against any of your repositories so the charts will not be rendered correctly in the UI. To do this you can exec into the container and run the jobs manually:<pre><code>podman exec -ti ayllu sh
284+ cd ~/repos/project/your-repository
285+ ayllu jobs run .
286+ </code></pre><h3 id=deployment-with-systemd><a aria-label="Anchor link for: deployment-with-systemd" class=zola-anchor href=#deployment-with-systemd>Deployment with Systemd</a></h3><p>TODO<h1 id=distribution-packages><a aria-label="Anchor link for: distribution-packages" class=zola-anchor href=#distribution-packages>Distribution Packages</a></h1><div class=warning>NOTE: Few distribution packages currently exist for Ayllu, any contributions in this regard would be gladly accepted!</div><h2 id=arch-linux><a aria-label="Anchor link for: arch-linux" class=zola-anchor href=#arch-linux>Arch Linux</a></h2><h6 id=release-package-unfinished><a aria-label="Anchor link for: release-package-unfinished" class=zola-anchor href=#release-package-unfinished>Release Package (Unfinished)</a></h6><p><a href=https://aur.archlinux.org/packages/ayllu>ayllu</a><h6 id=source-package-unfinished><a aria-label="Anchor link for: source-package-unfinished" class=zola-anchor href=#source-package-unfinished>Source Package (Unfinished)</a></h6><p><a href=https://aur.archlinux.org/packages/ayllu-git>ayllu-git</a><h1 id=from-source><a aria-label="Anchor link for: from-source" class=zola-anchor href=#from-source>From Source</a></h1><p>TODO</div></div></main><footer class=page-footer>2024, <a href=/projects/ayllu/blob/main/ATTRIBUTIONS.md>attributions</a></footer></div>
287\ No newline at end of file