general/other COUDINIT image, firstboot, and HTTP proxying

I'm setting up a short script that can create a FreeBSD guest instance for running poudriere without any user intervention. The sort of thing I can tell someone, "clone this repo, run this script" and it just sets itself up and starts doing work. Right now I have it grabbing the latest CLOUDINIT image and injecting the initial configuration via nuageinit.

For testing I'd really like to have the guest use a local Squid cache when grabbing things like packages, the ports tree, etc. What I can't figure out is how to set $HTTP_PROXY before the firstboot_pkg_upgrade script runs. Anybody know if this can be done?

I could set up Squid as a transparent poxy, but that's a different rabbit-hole...
 
What I can't figure out is how to set $HTTP_PROXY before the firstboot_pkg_upgrade
Do you mean here sysutils/firstboot-pkg-upgrade?

If that's the case, you could modify its rc(8) script to include the PKG_ENV variable from pkg.conf(5) ( similar to env AUTOCLEAN=ON ... in script ).
Rich (BB code):
OPTIONS

     PKG_ENV: Key/Value list
                  This tells pkg(8) to set key/values to be passed in the
                  environment.  This allow setting variables to configure the
                  http(s) fetcher.  Which accepts environment variables
                  compatible with fetch(3), e.g., HTTP_PROXY.  Default: not
                  set.
If your " firstboot_pkg_upgrade" is a custom script, you could use the packages script as a draft.
 
Indeed I did. It's installed in the stock CLOUDINIT-BASIC image and enabled in rc.conf.

If that's the case, you could modify its rc(8) script to include the PKG_ENV variable from pkg.conf(5) ( similar to env AUTOCLEAN=ON ... in script ).

You gave me an idea, so I did a bit of digging through /etc/rc and its includes, and I think I figured out a slightly better way:
  1. Append export HTTP_PROXY='http://<host ip>/' to /etc/rc.conf
  2. Raise SIGALRM, which causes rc to source /etc/rc.conf again
Here's the relevant portions of my user-data file:
YAML:
write_files:
  - path: /etc/rc.conf
    append: 1
    content: |
        export HTTP_PROXY='http://<host ip>/'
        echo "Setting $HTTP_PROXY: $HTTP_PROXY"
  - path: /etc/rc.conf.d/hostname
    append: 1
    content: |
        kill -ALRM $$

This appends the kill -ALRM $$ command to /etc/rc.conf.d/hostname, so when rc runs load_rc_config("hostname") (see rc.subr(8)) it sources the file and raises SIGALRM. I used hostname because for some reason raising the signal from /etc/rc.conf.d/firstboot_pkg_upgrade is too late to have an effect.

It's a bit of a hack, but it seems promising so far. I'll update after I set up Squid.
 
Back
Top