Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b45fbac

Browse files
committed
Upload TinyCore extensions to Bintray
1 parent ae561c7 commit b45fbac

File tree

12 files changed

+1895
-21
lines changed

12 files changed

+1895
-21
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,31 @@ jobs:
2525
cd ${GITHUB_WORKSPACE}/extensions/${{ matrix.extension }}
2626
make TC_VERSION=${{ matrix.tc_version }}
2727
28-
- uses: actions/upload-artifact@v1
29-
with:
30-
name: ${{ matrix.extension }}-tc${{ matrix.tc_version }}
31-
path: ${{ runner.temp }}/_github_home/artifacts/${{ matrix.extension }}-tc${{ matrix.tc_version }}
28+
- name: Download and setup JFrog CLI
29+
run: |
30+
curl -L -o jfrog 'https://api.bintray.com/content/jfrog/jfrog-cli-go/$latest/jfrog-cli-linux-amd64/jfrog?bt_package=jfrog-cli-linux-amd64'
31+
chmod +x jfrog
32+
sudo mv jfrog /usr/bin/jfrog
33+
sudo mkdir -p /etc/ssl/certs
34+
sudo ln -s /usr/local/etc/ssl/cacert.pem /etc/ssl/certs/ca-certificates.crt
35+
36+
- name: Upload the artifact to Bintray
37+
env:
38+
JFROG_CLI_LOG_LEVEL: DEBUG
39+
JFROG_CLI_OFFER_CONFIG: false
40+
run: |
41+
package=${{ matrix.extension }}-tc${{ matrix.tc_version }}
42+
version=$(cat ${HOME}/artifacts/config.version)
43+
source=$(cat ${HOME}/artifacts/config.source)
44+
license=$(cat ${HOME}/artifacts/config.license)
45+
jfrog bt config \
46+
--user ${{ secrets.BINTRAY_API_USER }} --key ${{ secrets.BINTRAY_API_KEY }}
47+
jfrog bt package-show on-prem/tinycore-extensions/${{ matrix.extension }} || \
48+
jfrog bt package-create \
49+
--vcs-url "https://github.com/${{ github.repository }}" \
50+
--licenses "${license}" \
51+
on-prem/tinycore-extensions/${{ matrix.extension }}
52+
jfrog bt upload \
53+
"${HOME}/artifacts/${package}/" \
54+
on-prem/tinycore-extensions/${{ matrix.extension }}/${version} \
55+
${{ matrix.tc_version }}/ || true

README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Cloud-init for On-Prem appliances using TinyCore Linux
2+
3+
![Build status](https://github.com/on-prem/tinycore-cloud-init/workflows/Extensions/badge.svg?branch=master)
4+
5+
This repo contains custom scripts to prepare [cloud-init](https://cloud-init.io/) for standard [TinyCore Linux](http://tinycorelinux.net) virtual appliances and cloud servers.
6+
7+
It is split into 3 sub-directories:
8+
9+
1. **extensions**: Build scripts for creating the required TinyCore `.tcz` extensions
10+
2. **overlay**: File and directory structure which should be copied directly into the rootfs
11+
3. **.github/workflows**: GitHub Actions workflow to automatically build each `.tcz` extension, and publish them to [Bintray](https://bintray.com/on-prem/tinycore-extensions)
12+
13+
## Cloud-init on TinyCore Linux
14+
15+
The current version of _cloud-init_ (`v19.x`) does not support TinyCore Linux. It is designed for systems such as Debian, CentOS, FreeBSD, etc. Lack of support for TinyCore leads us to two options:
16+
17+
* Modify _cloud-init_ and its _Python_ code to work with TinyCore Linux
18+
* Create custom scripts for operations specific to TinyCore Linux
19+
20+
Our use-case is to support immutable [On-Prem](https://on-premises.com) TinyCore appliances, which presents another set of problems since the system state is reset at every boot. The _Python_ interpreter is slow and the programming language is less than ideal, so tweaking it to work for TinyCore was not a good choice.
21+
22+
For this reason, we've created a set of simple custom _Shell_ scripts to handle most initialization tasks, while leveraging the few tasks _cloud-init_ handles well, such as detecting metadata and userdata from various cloud providers.
23+
24+
## Requirements
25+
26+
* TinyCore Linux 10.x x86-64
27+
* **overlay** directory structure added to rootfs
28+
* **python3.6.tcz** extension
29+
* **ifupdown.tcz**, **cloud-init.tcz**, **cloud-init-deps.tcz** extensions
30+
31+
## How it works
32+
33+
Once the overlay is added into the rootfs, only 3 extensions (and their dependencies) need to be loaded on boot:
34+
35+
* [ifupdown.tcz](https://dl.bintray.com/on-prem/tinycore-extensions/10.0-x86_64/:ifupdown.tcz)
36+
* [cloud-init.tcz](https://dl.bintray.com/on-prem/tinycore-extensions/10.0-x86_64/:cloud-init.tcz)
37+
* [cloud-init-deps.tcz](https://dl.bintray.com/on-prem/tinycore-extensions/10.0-x86_64/:cloud-init-deps.tcz)
38+
39+
The `/opt/booysync.sh` will run `cloud-init` and then try to setup networking through `/opt/network.sh`, which is simply calling `cloud-init` once more with different arguments. The reason for this is to provide backward compatibility for existing On-Prem TinyCore deployments.
40+
41+
**Note:** If there is no usage of the [network.tcz](https://github.com/on-prem/tinycore-network), [jidoteki-admin.tcz](https://github.com/on-prem/jidoteki-admin), or [jidoteki-admin-api.tcz](https://github.com/on-prem/jidoteki-admin-api) extensions, `/opt/network.sh` can be removed from `/opt/bootsync.sh` and replaced with:
42+
43+
```
44+
/usr/local/bin/cloud-init modules --mode config
45+
```
46+
47+
Each step in the _cloud-init_ runs can be found in `/etc/cloud/cloud.cfg`.
48+
49+
The `config` modules are `bootcmd` which are the actual _Shell_ scripts found in `/etc/cloud/scripts`.
50+
51+
Customizations can and _should_ be added to `custom.sh` and `custom-once.sh`. If it's not immediately obvious, the `once.sh` and `custom-once.sh` scripts will only run **once per boot**. Unlike typical _cloud-init_ installations, the _once_ scripts will **run again on reboot** (because the OS is immutable).
52+
53+
## What do these scripts configure
54+
55+
The scripts will configure the `NTP server` address, `DNS` nameservers, the `hostname` and `hosts` file, the `network` config for `eth0`, the `iptables` firewall, and additional `storage` (disk2) via `LVM, NFS, or AoE`.
56+
57+
The additional `storage` will not be configured unless the `xfsprogs.tcz`, `lvm2.tcz`, and `nfs-utils.tcz` extensions are loaded.
58+
59+
## Backups and restoring data
60+
61+
The data stored in `/var/lib/cloud` and `/run/cloud-init` should **not be backed up**, as it will prevent userdata and metadata from being altered on the Host OS, and any customized settings will not be retained on reboot.
62+
63+
The following files **can be backed up** (added to `/opt/.filetool.lst`):
64+
65+
* `etc/hosts`
66+
* `etc/sysconfig/network-config`
67+
* `etc/sysconfig/ntpserver`
68+
* `etc/sysconfig/storagetype`
69+
* `etc/hostname`
70+
* `etc/resolv.conf`
71+
72+
If they are backed up, on reboot they will overwrite any values from `userdata`, `metadata`, and `vendordata`, and will help speed up the boot process. Customizations to values (ex: `etc/hostname`) will also be retained.
73+
74+
If they are not backed up, the initial config will take a bit more time.
75+
76+
## Userdata, Metadata, Vendordata
77+
78+
The _Shell_ scripts provided for this _cloud-init_ deployment will read settings from various files on the system, including any userdata or vendordata provided to the system.
79+
80+
The order of precendence for reading configuration values are:
81+
82+
1. backed up files from `/opt/.filetool.lst`
83+
2. userdata from `/var/lib/cloud/instance/user-data.txt`
84+
3. vendordata from `/var/lib/cloud/seed/nocloud-net/vendor-data`
85+
86+
**Note:** Metadata is only currently used by _cloud-init_ to configure `SSH public-keys`. All other metadata is ignored, but still accessible to applications running on the TinyCore Linux appliance.
87+
88+
### Userdata
89+
90+
Tested with `EC2, Proxmox, and NoCloud`, the userdata will be discovered by _cloud-init_ and read directly from `/var/lib/cloud/instance/user-data.txt`. From testing, it appears _cloud-init_ handles Base64 decoding of userdata automatically provided by EC2.
91+
92+
**Note:** Userdata is **not parsed** by _cloud-init_, but rather read manually by various _Shell_ scripts. This means it is not possible for `userdata` to overwrite values from `/etc/cloud/cloud.cfg`, and it is not possible to provide `userdata` which contains a shell script or other malicious features. Userdata should only contain `key: value` pairs.
93+
94+
### Vendordata
95+
96+
The `vendor-data` should be added to the `/var/lib/cloud/seed/nocloud-net/` directory on the rootfs. It is also possible to add a `network-config` (v1 config) to that directory for pre-configuring the network.
97+
98+
**Note:** Similar to `userdata`, the `vendor-data` is **not parsed** by _cloud-init_ and should only contain `key: value` pairs (except for `network-config`, which is parsed by _cloud-init_'s `net-convert` tool).
99+
100+
## Extensions
101+
102+
All extensions are built from a `Makefile` under their respective directory. The extension's config values are stored in `config.make` (ex: version number, source URL). The extension's Open Source LICENSE file is also included.
103+
104+
The `Makefile` will load the `build.make` file which performs generic tasks such as adjusting file permissions, creating the `.tcz` squashfs file, and cleaning up.
105+
106+
**ifupdown.tcz** is taken directly from the Debian repositories, and built with a patch to remove the need for `run-parts`. This provides the `ifup, ifdown, ifquery` commands to TinyCore Linux, working with the typical Debian `/etc/network/interfaces` file, however it **can not run scripts**, for security reasons.
107+
108+
**cloud-init.tcz** is fetched from the official Canonical Cloud-Init repository, and built with standard Python 3 commands with no changes or patches. It contains the entire `cloud-init` installation without its dependencies.
109+
110+
**cloud-init-deps.tcz** is built similarly to `cloud-init.tcz` and contains all the dependencies for `cloud-init.tcz`.
111+
112+
### Building extensions
113+
114+
First, it is important to load the required _build_ tools in a TinyCore Linux environment:
115+
116+
```
117+
tce-load -wicl git compiletc coreutils
118+
```
119+
120+
To manually build an extension, `cd` into the directory of the extension and type:
121+
122+
```
123+
make TC_VERSION=10.0-x86_64
124+
````
125+
126+
The default `TC_VERSION` is `9.0-x86_64`, if that variable is omitted.
127+
128+
The files should be output to `$HOME/artifacts` in a subdirectory with the name of the extension and version of TinyCore. It will contain a simple `.info` file, the `md5 and sha256` hashes, the `.dep` files, and of course the `.tcz` extension file.
129+
130+
## GitHub workflow
131+
132+
The GitHub workflow runs three concurrent builds, one for each extension. It downloads the JFrog CLI tool if the extension was built correctly, and uploads the files to Bintray for further review (they are not published automatically).
133+
134+
# License
135+
136+
Everything in this repository is licensed under the MIT License, except for the `LICENSE` file of each individual extension.
137+
138+
[MIT License](LICENSE)
139+
140+
Copyright (c) 2020 Alexander Williams, Unscramble <license@unscramble.jp>

extensions/build.make

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PKG_CONFIG_PATH = /usr/local/lib/pkgconfig:/usr/lib/pkgconfig
77
TC_VERSION ?= 9.0-x86_64
88
artifact := $(HOME)/artifacts/$(package)-tc$(TC_VERSION)
99

10-
.PHONY: deps tcz perms clean
10+
.PHONY: deps tcz perms config clean
1111

1212
deps:
1313
sudo rm -rf $(artifact)
@@ -28,7 +28,14 @@ tcz:
2828
sha256sum $(package).tcz > $(package).tcz.sha256.txt && \
2929
find $(package) -not -type d -printf '%P\n' | sort > $(package).tcz.list && \
3030
echo "Version: $(VERSION)" > $(package).tcz.info
31+
$(MAKE) config
3132
$(MAKE) clean
3233

34+
config:
35+
cd $(HOME)/artifacts && \
36+
echo $(VERSION) > config.version && \
37+
echo $(package_source) > config.source && \
38+
echo $(package_license) > config.license
39+
3340
clean:
34-
sudo rm -rf $(package) $(package_name) $(artifact)/$(package)
41+
sudo rm -rf $(package) $(package_name) $(artifact)/$(package)

0 commit comments

Comments
 (0)