Monday, August 28, 2023

How to run a Python Docker Container on Azure Function


# How to upgrade Docker Container backed Azure Function

If you are using Azure Container registry to host your Azure Function then utilize these instructions to Upgrade them to Functions Runtime V4.

# Setup codebase

In hosts.json ensure this:
```
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.3.0, 4.0.0)"
  }
```

# Upgrade Production

### Upgrade The Extension Version
If all you are doing is the Production Slot This section all you need to do: (If you are upgrading a Slot set this value on your Slot and see below for more stuff you have to set):  

`FUNCTIONS_EXTENSION_VERSION=~4`

### Upgrade The Linux Version
When not working with a Container, instructions suggest to do this (don't do it):
~~`linux-fx-version=DOCKER|"Python|3.9"`~~

**But** when running a Docker Container **Set** this value (borrow the value from the URL of the Docker image in your current `Dockerfile`:

`linux-fx-version=DOCKER|mcr.microsoft.com/azure-functions/python:4-python3.10`

# Upgrade Slots. Not total upgrade.
You will have extra work to do if you are upgrading only one slot.

Set this value on the Production Slot:
`WEBSITE_OVERRIDE_STICKY_EXTENSION_VERSIONS=0`

Repeat for the Staging Slot:
`WEBSITE_OVERRIDE_STICKY_EXTENSION_VERSIONS=0`

# *Important*: Set Web Jobs Feature Flags.
If you are using Functions v2 syntax with an `function_app.py` and no `functions.json` files like you should be. You need to set the following value on the container. **If you don't** the Container won't be recognized and your Function App will just display a splash screen. 

This can be done through a new Configuration setting on the slot you are upgrading:
`AzureWebJobsFeatureFlags=EnableWorkerIndexing`

If you don't trust that this will work, some have put them in their `Dockerfile`'s `ENV` section like so:
```
ENV  
AzureWebJobsScriptRoot=/home/site/wwwroot  \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true  \
AzureWebJobsFeatureFlags=EnableWorkerIndexing  \
AzureWebJobsStorage=UseDevelopmentStorage=true
```

This one may not be needed:
`AzureWebJobsStorage=UseDevelopmentStorage=true`

Tuesday, November 3, 2020

Let's Docker Nging reverse proxy Laravel

docker compose laravel swag
docker compose laravel swag
  • Step 1: Wire up swag to your existing docker-compose multi container schema. When your ready flip your staging directive to true so you don't timeout your certbot by mistake if you are steadily destroying containers and remaking them.

    Add the following to the docker-compose.yml services directive:

  swag:
    image: linuxserver/swag
    container_name: swag
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - URL=advisory.nyc
      - SUBDOMAINS=wizdev,
      - VALIDATION=http
      - ONLY_SUBDOMAINS=true #optional
      - STAGING=false #optional
    volumes:
      - ./swag:/config
    ports:
      - 443:443
      - 80:80
    restart: unless-stopped
  swag:
    image: linuxserver/swag
    container_name: swag
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - URL=advisory.nyc
      - SUBDOMAINS=wizdev,
      - VALIDATION=http
      - ONLY_SUBDOMAINS=true #optional
      - STAGING=false #optional
    volumes:
      - ./swag:/config
    ports:
      - 443:443
      - 80:80
    restart: unless-stopped
  • Step 2
    Change the .env file to explicitly say site_location http:///somesite.you.com, and docker-compose run artisan config:clear

external assets will get blocked unless you do the following steps

        location / {
                proxy_pass http://wizdev.advisory.nyc:8080/;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                # try_files $uri $uri/ /index.html /index.php?$args =404;
        }
        

        location / {
                proxy_pass http://wizdev.advisory.nyc:8080/;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                # try_files $uri $uri/ /index.html /index.php?$args =404;
        }
        

Wednesday, February 5, 2020

VMWare Fusion Catalina VM, Jamf Pro

Get The Catalina Installer

Obtain an Install macOS Version Mojave from your /Applications folder. Or run cd; curl -O https://raw.githubusercontent.com/munki/macadmin-scripts/master/installinstallmacos.py; sudo python installinstallmacos.py --workdir /tmp

open /tmp

Double Click the Installer DMG, Drag the Install macOS Catalina from within the DMG to the Desktop. Feed that to VMWare Fusion 11.5 +.

You will need VMWare Fusion 11.5 or Higher, Pro or Regular doesn't matter.



Make The VMWare VM

open /tmp
Double click the dmg
Drag the actuall Install macOS Mojave to VMWare Fusion

Right after the OS installs I would suggest shutting down and making a clone.


Serialize

Shut the VM all the way down, use my script to set the serial number: https://github.com/zackn9ne/make_jamf_vm

Do All The Things


Start the VM and enroll in Jamf Pro

Thursday, January 2, 2020

Install Terminus Font Ubuntu

Terminus font is easy to install in ubuntu command line. Just do this: sudo apt-get install xfonts-terminus console-terminus

Wednesday, January 1, 2020

How to setup Unifi Docker AWS Controller (instead of using a cloudkey)

Set Up Your EC2

* get an aws ec2 supporting docker
* open the ports as described in the docker manifest: https://hub.docker.com/r/linuxserver/unifi-controller
* factory your USG
* ssh into your usg ubnt@usg-lan-ip-addr
* factory your USG from command line if you are feeling doubtful that the above worked: you can skip above step if you can somehow get in sudo syswrapper.sh restore-default
* set-inform http://$EC2IP:8080/inform
* head to https://$EC2IP:8443 and log in and now you can adopt your USG-3
* repeat the set-inform on your other Unifi branded devices and they will populate in the EC2 controller

Bonus Points Upgrading your (Unifi Device)

* while your ssh connection is live on the device, google unifi upgrade and get the link to the proper firmware, currently it's here https://downloads.ui.com/unifi
* upgrade https://$FIRMWARE (where $FIRMWARE) is the url of the firmware

What if the IPADDRESS of my Controller Changed, like I forgot To Set A Elastic IP?

It's all good you can SSH into your local devices using probably the last IP address shown in your messed up controller. Note when the devices get adopted the ssh creds change from default to something like superadmin, and a hash found in the following screen, so grab the ssh creds like so:



They let you view the password in plain text, and ssh right in, redo the set-inform command with the new URL and you will be all set. Do it per each device.

Thursday, November 14, 2019

How to install youtube-dl on Windows (WSL)

Install Python2 and then curl install youtube-dl to the /usr/local/bin directory
* sudo apt install python -y
* sudo apt install mpv -y
* sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+rx /usr/local/bin/youtube-dl
* youtube-dl all the things

Specific examples of how to use youtube-dl
* youtube-dl https://www.youtube.com/watch?v=KK5KTQGuXSQ --format ("bestvideo[width>=1920]"/bestvideo)+bestaudio/best --download-archive archive.txt --output %%(uploader)s/%%(upload_date)s.%%(title)s.%%(id)s.%%(ext)s --add-metadata --write-info-json --write-description --write-annotation --write-thumbnail --merge-output-format mkv --ignore-errors

You can use my Shell Script here too
#!/bin/sh
echo this you put $1
CORE='youtube-dl'
FIRST='${1}'
SECOND='-f bestvideo+bestaudio/best -i --prefer-ffmpeg --write-sub --all-subs --convert-subs srt --add-metadata --write-description --write-annotations --write-thumbnail -v'
echo this is second $SECOND

echo this is command: ${CORE} ${1} $SECOND
${CORE} ${1} $SECOND


#end

Command syntax is $ sh youtube-dl.sh https://full-youtube-link

Thursday, November 7, 2019

How to setup GNU Emacs on Windows 10

  • You want to C-h v (describe variable) user-init-file 
  • Put the path to your real init files in there eg, (load "c:/emacs/bin/init.el")
  • Source additional init files, eg, (load "c:/emacs/bin/_org.el"), (load "c:/emacs/bin/_erc.el")