Skip to content

30 a basic web server should be brought online in alpine after #41

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Init python
hosts: all
gather_facts: false

tasks:
# We should try to inlcude python in the Alpine image by default
- name: Install python3
raw: test -e /usr/bin/python3 || apk add --no-cache python3
8 changes: 8 additions & 0 deletions repo-server-bootstrap-ncl-issue-20/deploy/ansible/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Init python
import_playbook: init-python.yml

- name: Setup OS environment
import_playbook: setup-os-env.yml

- name: Setup webserver container
import_playbook: setup-webserver.yml
13 changes: 0 additions & 13 deletions repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml

This file was deleted.

19 changes: 19 additions & 0 deletions repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-os-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: Setup OS
hosts: all

tasks:
- name: Install openntpd
community.general.apk:
name: openntpd
state: present

- name: Setup NTP
command: setup-ntp
args:
creates: /etc/ntpd.conf

- name: Add community repository
lineinfile:
path: /etc/apk/repositories
line: "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/"
state: present
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: Setup webserver container
hosts: all

tasks:
- name: Ensure podman is present
community.general.apk:
name: podman
state: present

- name: Enable and start cgroups service
service:
name: cgroups
enabled: true
state: started

- name: Ensure /srv/www directory exists
file:
path: /srv/www
state: directory

- name: Create index.html
copy:
dest: /srv/www/index.html
content: "Hello\n"

- name: Start apache container with podman
containers.podman.podman_container:
name: apache
image: docker.io/library/httpd:2.4
state: started
restart_policy: unless-stopped
detach: true
ports:
- "80:80"
volumes:
- /srv/www:/usr/local/apache2/htdocs/
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# DNS ping
for i in $dns1 $dns2; do
ebegin "Awaiting accessible DNS at $i"
while ! ping -c 1 -w 1 -q "$i" > /dev/null 2>&1; do
sleep 1
done
eend $?

echo "nameserver $i" >> /etc/resolv.conf
done

# Alpine mirror ping
if [[ -n "$ALPINE_REPO" ]] && [[ "$ALPINE_REPO" != "auto" ]]; then
local alpine_repo_domain=$(echo "$ALPINE_REPO" | sed -E 's#https?://([^/]+).*#\1#')
ebegin "Awaiting accessible Alpine repo at $alpine_repo_domain"
while ! ping -c 1 -w 1 -q "$alpine_repo_domain" > /dev/null 2>&1; do
sleep 1
done
eend $?
fi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# https://wiki.alpinelinux.org/wiki/PXE_boot

# --- Network configuration (static IP) ---
set static-iface
set static-iface eth0
set static-ip 192.168.0.248
set static-gw 192.168.0.1
set static-mask 255.255.255.0
Expand Down
2 changes: 1 addition & 1 deletion repo-server-bootstrap-ncl-issue-20/internal/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func bootstrap(lom *lom.LOM) error {

// Run ansible playbook
fmt.Println("Running playbook")
cmd := exec.Command("ansible-playbook", "-i", addr+",", "--private-key", "/app/key", "./ansible/playbook.yml")
cmd := exec.Command("ansible-playbook", "-i", addr+",", "--private-key", "/app/key", "./ansible/main.yml")
cmd.Env = append(cmd.Env, "ANSIBLE_SSH_COMMON_ARGS='-o StrictHostKeyChecking=no'")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down