Skip to content
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

eCR Viewer setup script + variable pattern setting 🖌️ #51

Merged
merged 20 commits into from
Mar 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2afb855
wip
alismx Feb 24, 2025
81a6d84
feat: Update environment vars configurations and services version in …
alismx Feb 25, 2025
cb2bede
feat: Update docker compose files with dynamic version, refactor fold…
alismx Feb 26, 2025
292d071
feat(workflows): add multiple packer build jobs and improve file orga…
alismx Feb 26, 2025
9900a9f
refactor: rename 'packer_build_main' to 'packer_build' in GitHub acti…
alismx Feb 26, 2025
ac3c5b6
feat: parameterize service name in docker compose file
alismx Feb 26, 2025
98511df
feat: add workflow_dispatch event to packMachines.yml
alismx Feb 26, 2025
0b98659
feat: append dibbs_version to vm_name in ubuntu server config
alismx Feb 26, 2025
3f80641
feat: update output directory path in ubuntu.pkr.hcl config file
alismx Feb 26, 2025
da2b1ed
feat: modify output directory path in packer config
alismx Feb 26, 2025
b38253c
feat(docker): update environment variable management in dibbs-ecr-viewer
alismx Feb 28, 2025
9b732ed
feat(docker): add service and version details to ecr viewer, modify b…
alismx Feb 28, 2025
9bc52ba
feat: enhance configuration for ecr-viewer and update build script
alismx Feb 28, 2025
e8028b4
chore(docker): remove trailing spaces and export environment variables
alismx Feb 28, 2025
ae56369
feat: Export env variables for docker compose and persist reboot
alismx Feb 28, 2025
d425339
chore: clean up environment variables in ecr-viewer.env
alismx Feb 28, 2025
71b2aa9
refactor: rename environment files and script variables to match new …
alismx Mar 1, 2025
6c66db2
refactor: rename environment files and update references in .gitignor…
alismx Mar 1, 2025
32e5216
feat: refactor packer workflow and remove redundant variable declarat…
alismx Mar 3, 2025
3591b1f
docs: correct typo in wizard.sh comment about clear_dot_env function
alismx Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip
  • Loading branch information
alismx committed Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
kosmydel Jakub Kosmydel
commit 2afb855ebdc7df1482787a4d881db57eca98f423
13 changes: 5 additions & 8 deletions .github/workflows/dibbsVm.yml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ permissions:
contents: read

jobs:

build:
runs-on: ubuntu-latest

@@ -25,11 +26,7 @@ jobs:
echo "::set-output name=version::$version"

- name: Build dibbs-vm for dibbs-ecr-viewer
if: ${{ steps.extract.outputs.service == 'dibbs-ecr-viewer' }}
run: |
echo "Building dibbs-vm version ${{ steps.extract.outputs.version }} for ${{ steps.extract.outputs.service }}"

- name: Build dibbs-vm for dibbs-query-connector
if: ${{ steps.extract.outputs.service == 'dibbs-query-connector' }}
run: |
echo "Building dibbs-vm version ${{ steps.extract.outputs.version }} for ${{ steps.extract.outputs.service }}"
uses: ./.github/workflows/packMachines.yml
with:
service: ${{ steps.extract.outputs.service }}
version: ${{ steps.extract.outputs.version }}
10 changes: 9 additions & 1 deletion .github/workflows/packMachines.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,14 @@ on:
push:
branches:
- main
workflow_call:
inputs:
service:
required: true
type: string
version:
required: true
type: string

permissions:
contents: read
@@ -51,6 +59,6 @@ jobs:
## TODO: Add matrixed provisioner build here
- name: Build Packer Image
working-directory: ./packer
run: packer build ./ubuntu.pkr.hcl
run: packer build --var dibbs_service=${{ inputs.service }} --var dibbs_version=${{ inputs.version }} ./ubuntu.pkr.hcl

## TODO: Decide how to export artifact.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packer/ubuntu-server/build/*
52 changes: 52 additions & 0 deletions docker/ecr-viewer/wizard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# AWS_REGION=${AWS_REGION}
# ECR_BUCKET_NAME=${ECR_BUCKET_NAME}
# APP_ENV=${APP_ENV}
# NBS_PUB_KEY=${NBS_PUB_KEY}
# NEXT_PUBLIC_BASEPATH=/ecr-viewer
# CONFIG_NAME=${CONFIG_NAME}
# DATABASE_URL=${DATABASE_URL}
# SQL_SERVER_USER=${SQL_SERVER_USER}
# SQL_SERVER_PASSWORD=${SQL_SERVER_PASSWORD}
# SQL_SERVER_HOST=${SQL_SERVER_HOST}

read -p "AWS_REGION: " choice
echo "AWS_REGION: $choice"

read -p "ECR_BUCKET_NAME: " choice
echo "ECR_BUCKET_NAME: $choice"

read -p "APP_ENV: " choice
echo "APP_ENV: $choice"

read -p "NBS_PUB_KEY: " choice
echo "NBS_PUB_KEY: $choice"

read -p "CONFIG_NAME: " choice
echo "CONFIG_NAME: $choice"

read -p "Database type (PostgreSQL, SQLServer): " choice
echo "Database type: $choice"

if [ "$choice" == "PostgreSQL" ]; then
echo "PostgreSQL"
read -p "DATABASE_URL: " choice
echo "DATABASE_URL: $choice"
elif [ "$choice" == "SQLServer" ]; then
echo "SQLServer"
read -p "SQL_SERVER_USER: " choice
echo "SQL_SERVER_USER: $choice"

read -p "SQL_SERVER_PASSWORD: " choice
echo "SQL_SERVER_PASSWORD: $choice"

read -p "SQL_SERVER_HOST: " choice
echo "SQL_SERVER_HOST: $choice"
else
echo "Invalid database type. Please choose either PostgreSQL or SQLServer."
exit 1
fi


docker compose up -d
26 changes: 20 additions & 6 deletions packer/ubuntu-server/scripts/provision.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/bin/bash

# loop through all .env files and export the variables
for file in $(find . -name "*.env"); do
export $(cat $file | xargs)
# echo $file
done

# Adjust Docker group permissions.
groupadd docker
usermod -aG docker ubuntu
@@ -8,12 +16,18 @@ systemctl enable docker.service
systemctl enable containerd.service
systemctl start docker.service

# Clone Compose files
cd ~
mkdir dev
cd dev
git clone https://github.com/CDCgov/dibbs-vm.git
cd dibbs-vm/docker/ecr-viewer
# Check if DIBBS_SERVICE is valid
# dibbs-ecr-viewer
# dibbs-query-connect
if [ "$DIBBS_SERVICE" == "dibbs-ecr-viewer" ] || [ "$DIBBS_SERVICE" == "dibbs-query-connect" ]; then
echo "DIBBS Service is valid. DIBBS_SERVICE=$DIBBS_SERVICE"
else
echo "DIBBS Service is not valid. DIBBS_SERVICE=$DIBBS_SERVICE" && exit 1
fi

# Clone the dibbs-vm repository
git clone --branch $DIBBS_VERSION https://github.com/CDCgov/dibbs-vm.git
cd "dibbs-vm/docker/$(echo "$DIBBS_SERVICE" | sed -E 's/.*?dibbs-//')" || exit

# Trigger initial docker compose to pull image data
docker compose up -d
17 changes: 15 additions & 2 deletions packer/ubuntu-server/ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -31,8 +31,18 @@ packer {
}
}

variable "dibbs_service" {
description = "The name of the service to be built"
type = string
}

variable "dibbs_version" {
description = "The version of the service to be built"
type = string
}

source "qemu" "iso" {
vm_name = "ubuntu-2404-ecrViewer.raw"
vm_name = "ubuntu-2404-${ var.dibbs_service }.raw"
# Uncomment this block to use a basic Ubuntu 24.04 cloud image
# iso_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
# iso_checksum = "sha256:28d2f9df3ac0d24440eaf6998507df3405142cf94a55e1f90802c78e43d2d9df"
@@ -83,12 +93,15 @@ build {
sources = [
"source.qemu.iso"
]

provisioner "shell" {
only = ["qemu.iso"]
scripts = [
"scripts/provision.sh"
]
environment_vars = [
"DIBBS_SERVICE=${ var.dibbs_service }",
"DIBBS_VERSION=${ var.dibbs_version }"
]
execute_command = "echo 'ubuntu' | {{.Vars}} sudo -S -E bash '{{.Path}}'"
}

40 changes: 40 additions & 0 deletions utils/convert_raw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# sudo apt install genisoimage
mkdir -p /media/cdrom
mkdir -p tmp

cp ../packer/ubuntu-server/build/os-base/ubuntu-2404-ecrViewer.raw tmp/ubuntu-2404-ecrviewer.raw

# Set up loop device manually
sudo losetup -P /dev/loop0 tmp/ubuntu-2404-ecrviewer.raw

# Check for partitions and mount the first partition
if [ -e /dev/loop0p1 ]; then
sudo mount /dev/loop0p1 /media/cdrom
elif [ -e /dev/loop0p2 ]; then
sudo mount /dev/loop0p2 /media/cdrom
elif [ -e /dev/loop0p3 ]; then
sudo mount /dev/loop0p3 /media/cdrom
else
sudo mount /dev/loop0 /media/cdrom
fi

sudo mount -o loop tmp/ubuntu-2404-ecrviewer.raw /media/cdrom
mkisofs -f -iso-level=1 -J -r -T -pad -v -o image.iso /media/cdrom

# Clean up
sudo umount /media/cdrom
sudo losetup -d /dev/loop0










sudo losetup -f ubuntu-2404-ecrViewer.raw

sudo dd if=/dev/loop0 of=ubuntu-image.iso status=progress