-
Notifications
You must be signed in to change notification settings - Fork 2
DRAFT: Add Packer build and upload workflow for Proxmox templates #80
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
cmyers-mieweb
wants to merge
6
commits into
main
Choose a base branch
from
cmyers_issue63
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca05763
DRAFT: Add Packer build and upload workflow for Proxmox templates
28b0c52
Add README and update Rocky9 template name
ff63249
Migrate Proxmox template upload API from Python to Node.js
4f53869
Enforce SSL verification for Proxmox API requests
3975740
Move packer files to top-level directories
6d61e47
Merge branch 'main' into cmyers_issue63
cmyers-mieweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Migrate Proxmox template upload API from Python to Node.js
Replaces Python scripts proxmox_upload.py and proxmox_utils.py with Node.js equivalents proxmox_upload.js and proxmox_utils.js for uploading LXC templates to Proxmox. Adds package.json for dependencies and updates CI workflow to trigger on changes in the packer directory. Minor improvements to Ansible provisioning and Packer variable files.
- Loading branch information
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
container-creation/intern-phxdc-pve1/packer/.github/workflows/build-templates.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
container-creation/intern-phxdc-pve1/packer/api/proxmox_upload.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env node | ||
| // api/proxmox_upload.js | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const { getNodes, getStorages, uploadTemplate, chooseDefaultStorage } = require('./proxmox_utils'); | ||
|
|
||
| function parseArgs() { | ||
| const argv = process.argv.slice(2); | ||
| const out = {}; | ||
| for (let i = 0; i < argv.length; i++) { | ||
| const a = argv[i]; | ||
| if (a === '--file' && argv[i + 1]) { | ||
| out.file = argv[i + 1]; | ||
| i++; | ||
| } | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| async function main() { | ||
| const args = parseArgs(); | ||
| if (!args.file) { | ||
| console.error('Error: --file is required'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const filepath = args.file; | ||
| if (!fs.existsSync(filepath)) { | ||
| console.error(`Error: file not found: ${filepath}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`Starting template upload for: ${filepath}`); | ||
|
|
||
| try { | ||
| const nodes = await getNodes(); | ||
| if (!nodes || !nodes.length) { | ||
| console.error('Error: No Proxmox nodes found.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`Found nodes: ${nodes.join(', ')}`); | ||
|
|
||
| for (const node of nodes) { | ||
| console.log(`--- Processing Node: ${node} ---`); | ||
| const storagesList = await getStorages(node); | ||
| const storage = chooseDefaultStorage(storagesList); | ||
| if (!storage) { | ||
| console.warn(`Warning: No suitable storage found on node ${node}. Skipping.`); | ||
| continue; | ||
| } | ||
|
|
||
| console.log(`Uploading to ${node}:${storage}...`); | ||
| try { | ||
| const result = await uploadTemplate(node, storage, filepath); | ||
| console.log(`Successfully uploaded to ${node}:${storage}. Task: ${JSON.stringify(result.data || result)}`); | ||
| } catch (e) { | ||
| console.error(`Error uploading to ${node}:${storage}: ${e.message || e}`); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error(`An unexpected error occurred: ${e.message || e}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log('Template upload process finished.'); | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| main(); | ||
| } |
48 changes: 0 additions & 48 deletions
48
container-creation/intern-phxdc-pve1/packer/api/proxmox_upload.py
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
container-creation/intern-phxdc-pve1/packer/api/proxmox_utils.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // api/proxmox_utils.js | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const axios = require('axios'); | ||
| const FormData = require('form-data'); | ||
| const https = require('https'); | ||
|
|
||
| const API_URL = process.env.PROXMOX_API_URL; | ||
| const TOKEN_ID = process.env.PROXMOX_TOKEN_ID; | ||
| const TOKEN_SECRET = process.env.PROXMOX_TOKEN_SECRET; | ||
|
|
||
| if (!API_URL || !TOKEN_ID || !TOKEN_SECRET) { | ||
| // Do not throw; allow functions to be imported but fail loudly when used. | ||
| // Console a warning to help debugging. | ||
| console.warn('Warning: PROXMOX_API_URL, PROXMOX_TOKEN_ID or PROXMOX_TOKEN_SECRET is not set. Requests will fail.'); | ||
| } | ||
|
|
||
| const HEADERS = { | ||
| Authorization: `PVEAPIToken=${TOKEN_ID}=${TOKEN_SECRET}`, | ||
| }; | ||
|
|
||
| // Accept self-signed / insecure if needed (mirrors requests verify=False) | ||
| const httpsAgent = new https.Agent({ rejectUnauthorized: false }); | ||
|
|
||
| async function getNodes() { | ||
| const resp = await axios.get(`${API_URL}/nodes`, { headers: HEADERS, httpsAgent }); | ||
| const data = resp.data && resp.data.data ? resp.data.data : []; | ||
| return data.map(n => n.node); | ||
| } | ||
|
|
||
| async function getStorages(node) { | ||
| const resp = await axios.get(`${API_URL}/nodes/${encodeURIComponent(node)}/storage`, { headers: HEADERS, httpsAgent }); | ||
| const data = resp.data && resp.data.data ? resp.data.data : []; | ||
| return data.map(s => s.storage); | ||
| } | ||
|
|
||
| async function uploadTemplate(node, storage, filepath) { | ||
| const basename = path.basename(filepath); | ||
| const form = new FormData(); | ||
|
|
||
| // Append file stream | ||
| form.append('content', fs.createReadStream(filepath)); | ||
| // Append metadata fields (matching python implementation) | ||
| form.append('content', 'vztmpl'); | ||
| form.append('filename', basename); | ||
|
|
||
| const headers = Object.assign({}, HEADERS, form.getHeaders()); | ||
|
|
||
| const resp = await axios.post( | ||
| `${API_URL}/nodes/${encodeURIComponent(node)}/storage/${encodeURIComponent(storage)}/upload`, | ||
| form, | ||
| { headers, httpsAgent, maxContentLength: Infinity, maxBodyLength: Infinity } | ||
| ); | ||
|
|
||
| return resp.data; | ||
| } | ||
|
|
||
| function chooseDefaultStorage(storages) { | ||
| if (!Array.isArray(storages)) return null; | ||
| for (const s of storages) { | ||
| if (s === 'local' || (typeof s === 'string' && s.toLowerCase().includes('local'))) return s; | ||
| } | ||
| return storages.length ? storages[0] : null; | ||
| } | ||
|
|
||
| module.exports = { | ||
| getNodes, | ||
| getStorages, | ||
| uploadTemplate, | ||
| chooseDefaultStorage, | ||
| }; | ||
49 changes: 0 additions & 49 deletions
49
container-creation/intern-phxdc-pve1/packer/api/proxmox_utils.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "intern-phxdc-pve1-packer-api", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "description": "Node utilities to upload Proxmox LXC templates (used for CI)", | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "dependencies": { | ||
| "axios": "^1.6.0", | ||
| "form-data": "^4.0.0" | ||
| }, | ||
| "scripts": { | ||
| "upload": "node api/proxmox_upload.js" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
container-creation/intern-phxdc-pve1/packer/vars/rocky9.auto.pkrvars.hcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| rocky_release = "9" | ||
| template_name = "rocky9-lxc" | ||
| rootfs_dir = "/tmp/rocky9-rootfs" | ||
| hostname = "template-rocky9" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.