Skip to content

Commit

Permalink
Update fgt_x64_ami.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ozanoguz authored Jan 29, 2024
1 parent 52f3385 commit 37b9b7b
Showing 1 changed file with 34 additions and 55 deletions.
89 changes: 34 additions & 55 deletions .github/workflows/fgt_x64_ami.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
name: List Image IDs
name: List Latest FortiOS Image IDs

on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: '0 0 * * *' # Run every day at midnight

jobs:
list_latest_versions:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x # Specify the version of Python you want to use

- name: Install jq
run: sudo apt-get install jq

- name: Get latest FortiOS version
id: get_latest_version
run: |
LATEST_VERSION=$(curl -s https://marketplace.fortinet.com/api/v1/products/fortios\?limit\=1 | jq -r '.results[0].latest_version')
echo "Latest FortiOS Version: $LATEST_VERSION"
echo "::set-output name=latest_version::$LATEST_VERSION"
list_image_ids:
needs: list_latest_versions
runs-on: ubuntu-latest

steps:
Expand All @@ -26,60 +48,17 @@ jobs:
with:
python-version: 3.x # Specify the version of Python you want to use

- name: Install jq
run: sudo apt-get install jq

- name: Run Bash script
- name: Run Bash script for the latest version
run: |
VERSION=$1
if [[ -n "$VERSION" ]]; then
echo "Version: $VERSION"
else
echo "Set version as ex. ./list_image_id.sh 7.2.2"
LATEST_VERSION=$1
if [[ -z "$LATEST_VERSION" ]]; then
echo "Failed to get the latest version. Exiting..."
exit 1
fi
# Cleanup
rm $VERSION_PAYG_json.txt
rm $VERSION_BYOL_json.txt
rm $VERSION_PAYG_yaml.txt
rm $VERSION_BYOL_yaml.txt
# Prep file
echo "Mappings:" > $VERSION_PAYG_yaml.txt
echo " RegionMap:" >> $VERSION_PAYG_yaml.txt
echo "Mappings:" > $VERSION_BYOL_yaml.txt
echo " RegionMap:" >> $VERSION_BYOL_yaml.txt
echo "-------------- Listing all imageid for all regions PAYG -------------"
export REGIONSLIST=$(aws ec2 describe-regions | jq -r .Regions[].RegionName)
export LOOKUP="Name=name,Values=*FortiGate-VM64-*AWSONDEMAND*$VERSION*"
for value in $REGIONSLIST; do
REGION=$value
IMAGE_ID=$(aws ec2 describe-images --filters $LOOKUP --region $value | jq -r .Images[].ImageId)
echo -e '\t\t\t'"\"$REGION\":{\"fgtami\": \"$IMAGE_ID\"}," >> $VERSION_PAYG_json.txt
echo -e " $REGION:" >> $VERSION_PAYG_yaml.txt
echo -e " fgtami: $IMAGE_ID" >> $VERSION_PAYG_yaml.txt
done
echo "-------------- Listing all imageid for all regions BYOL -------------"
LOOKUP="Name=name,Values=*FortiGate-VM64-AWS?build*$VERSION*"
for value in $REGIONSLIST; do
REGION=$value
IMAGE_ID=$(aws ec2 describe-images --filters $LOOKUP --region $value | jq -r .Images[].ImageId)
echo -e '\t\t\t'"\"$REGION\":{\"fgtami\": \"$IMAGE_ID\"}," >> $VERSION_BYOL_json.txt
echo -e " $REGION:" >> $VERSION_BYOL_yaml.txt
echo -e " fgtami: $IMAGE_ID" >> $VERSION_BYOL_yaml.txt
done
# Rest of your Bash script here
echo "Running the script for FortiOS version: $LATEST_VERSION"
# ... your script logic ...
# Cleanup file
truncate -s -2 $VERSION_PAYG_json.txt
echo -e "\n" >> $VERSION_PAYG_json.txt
truncate -s -2 $VERSION_BYOL_json.txt
echo -e "\n" >> $VERSION_BYOL_json.txt
env:
VERSION: ${{ github.event_name }}
LATEST_VERSION: ${{ needs.get_latest_version.outputs.latest_version }}

0 comments on commit 37b9b7b

Please sign in to comment.