Skip to content

Commit

Permalink
Merge pull request #21 from microsoft/hostsvc-position-build-config
Browse files Browse the repository at this point in the history
Enabling service build with base
  • Loading branch information
bigtallcampbell authored Jun 17, 2024
2 parents d1e59af + fea78a2 commit b9297c4
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 14 deletions.
10 changes: 9 additions & 1 deletion .devcontainer/features/spacefx-dev/updateContent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function pull_extra_build_artifacts(){
continue
fi
info_log "...adding build artifact '${artifact}' to stage_spacefx cmd..."
STAGE_SPACE_FX_CMD_EXTRAS="${STAGE_SPACE_FX_CMD_EXTRAS} --build-artifact ${artifact}"
STAGE_SPACE_FX_CMD_EXTRAS="${STAGE_SPACE_FX_CMD_EXTRAS} --artifact ${artifact}"
done

info_log "END: ${FUNCNAME[0]}"
Expand Down Expand Up @@ -218,6 +218,14 @@ function main() {
install_extra_packages

if [[ "${CLUSTER_ENABLED}" == "false" ]]; then
if [[ ${#DOWNLOAD_ARTIFACTS[@]} -ne 0 ]]; then
pull_extra_build_artifacts
info_log "Starting stage_build_artifact.sh..."
run_a_script_on_host "${SPACEFX_DIR}/scripts/stage/stage_build_artifact.sh ${STAGE_SPACE_FX_CMD_EXTRAS}"
info_log "...stage_build_artifact.sh completed successfully"
fi

# Drop out of the script if we're not deploying to a cluster
return
fi

Expand Down
9 changes: 6 additions & 3 deletions build/build_containerImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ EXTRA_PKGS=""
ANNOTATION_CONFIG=""
BUILDDATE_VALUE=$(date -u +'%Y%m%dT%H%M%S')
IS_BASE_SVC_CONTAINER=false
SPACEFX_DEV_ENABLED=true

############################################################
# Help #
Expand All @@ -48,6 +49,7 @@ function show_help() {
echo "--annotation-config [OPTIONAL] Filename of the annotation configuration to add to spacefx-config.json. File must reside within ${SPACEFX_DIR}/config/github/annotations"
echo "--build-arg | -b [OPTIONAL] Individual name/value pairs to pass as build arguments to the docker build command. Once key-value-pair per build_arg like --build-arg key=value"
echo "--add-base-suffix [OPTIONAL] Add the base image suffix to the image tag. Used for building base containers for Azure Orbital Space SDK Services"
echo "--no-spacefx-dev [OPTIONAL] Disable spacefx-dev feature provisioning if present. Useful in CI/CD pipelines to speed up builds that are coming from ./build/dotnet/build_app.sh"
echo "--help | -h [OPTIONAL] Help script (this screen)"
echo
exit 1
Expand All @@ -63,6 +65,9 @@ while [[ "$#" -gt 0 ]]; do
--add-base-suffix)
IS_BASE_SVC_CONTAINER=true
;;
--no-spacefx-dev)
SPACEFX_DEV_ENABLED=false
;;
--annotation-config)
shift
ANNOTATION_CONFIG=$1
Expand Down Expand Up @@ -368,11 +373,9 @@ function main() {
fi

write_parameter_to_log DEST_REPO

provision_emulator


if [[ -f "${REPO_DIR}/.devcontainer/devcontainer.json" ]]; then
if [[ -f "${REPO_DIR}/.devcontainer/devcontainer.json" ]] && [[ "${SPACEFX_DEV_ENABLED}" == true ]]; then
info_log "Checking for spacefx-dev..."
run_a_script "devcontainer read-configuration --workspace-folder ${REPO_DIR} | jq '.configuration.features | to_entries[] | select(.key | contains(\"spacefx-dev\")) | true'" has_spacefx_feature --ignore_error
info_log "Result: ${has_spacefx_feature}"
Expand Down
81 changes: 73 additions & 8 deletions build/dotnet/build_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function show_help() {
# Display Help
echo "Builds and pushes the Azure Orbital Space SDK container images and nuget packages"
echo
echo "Syntax: bash ./build/dotnet/build_app.sh --repo-dir ~/repos/project_source_code --app-project src/project.csproj --nuget-project src/project.csproj --architecture amd64 --output ./tmp/someDirectory --app-version 0.0.1"
echo "Syntax: bash ./build/dotnet/build_app.sh --repo-dir ~/repos/project_source_code --app-project src/project.csproj --nuget-project src/project.csproj --architecture amd64 --output-dir ./tmp/someDirectory --app-version 0.0.1"
echo "options:"
echo "--annotation-config [OPTIONAL] Filename of the annotation configuration to add to spacefx-config.json. File must reside within ${SPACEFX_DIR}/config/github/annotations"
echo "--architecture | -a [REQUIRED] The processor architecture for the final build. Must be either arm64 or amd64"
Expand Down Expand Up @@ -312,7 +312,7 @@ function provision_devcontainer(){


############################################################
# Helper function to update an option in devcontainer.json
# Build the nuget package project
############################################################
function build_nuget_package(){

Expand All @@ -329,9 +329,34 @@ function build_nuget_package(){
done

info_log "Building nuget package for project '${project}'..."
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json mkdir -p ${BUILD_OUTPUT_DIR}"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet restore \"${CONTAINER_WORKSPACE_FOLDER}/${nuget_pkg}\" /p:Version=${APP_VERSION}"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet pack \"${CONTAINER_WORKSPACE_FOLDER}/${nuget_pkg}\" /p:Version=${APP_VERSION} --output \"${BUILD_OUTPUT_DIR}/\" --configuration Release"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json mkdir -p ${BUILD_OUTPUT_DIR}/nuget"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet restore \"${CONTAINER_WORKSPACE_FOLDER}/${project}\" /p:Version=${APP_VERSION}"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet build \"${CONTAINER_WORKSPACE_FOLDER}/${project}\" /p:Version=${APP_VERSION} --output \"${BUILD_OUTPUT_DIR}/nuget\" --configuration Release"
info_log "...project ${project} successfully generated"

}

############################################################
# Build the app that will be backed into a container
############################################################
function build_app(){

local project=""

while [[ "$#" -gt 0 ]]; do
case $1 in
--project)
shift
project=$1
;;
esac
shift
done

info_log "Building app '${project}'..."
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json mkdir -p ${BUILD_OUTPUT_DIR}/app"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet restore \"${CONTAINER_WORKSPACE_FOLDER}/${project}\" /p:Version=${APP_VERSION}"
run_a_script "devcontainer exec --workspace-folder ${REPO_DIR} --config ${SPACEFX_DIR}/tmp/${APP_NAME}/devcontainer.json dotnet build \"${CONTAINER_WORKSPACE_FOLDER}/${project}\" /p:Version=${APP_VERSION} --output \"${BUILD_OUTPUT_DIR}/app\" --configuration Release"
info_log "...project ${project} successfully generated"

}
Expand All @@ -342,9 +367,21 @@ function build_nuget_package(){
function copy_to_output_dir(){
info_log "START: ${FUNCNAME[0]}"

local subfolder=""

while [[ "$#" -gt 0 ]]; do
case $1 in
--subfolder)
shift
subfolder=$1
;;
esac
shift
done

info_log "Copying contents of build output dir '${BUILD_OUTPUT_DIR}' to requested output directory '${OUTPUT_DIR}'..."
run_a_script "mkdir -p ${OUTPUT_DIR}"
run_a_script "cp -r ${BUILD_OUTPUT_DIR}/* ${OUTPUT_DIR}/"
run_a_script "mkdir -p ${OUTPUT_DIR}/${subfolder}"
run_a_script "cp -r ${BUILD_OUTPUT_DIR}/${subfolder}* ${OUTPUT_DIR}/${subfolder}"
info_log "...successfully copied '${BUILD_OUTPUT_DIR}' to '${OUTPUT_DIR}'. "

info_log "END: ${FUNCNAME[0]}"
Expand Down Expand Up @@ -426,14 +463,42 @@ function main() {
build_nuget_package --project "${NUGET_PROJECT}"
done

copy_to_output_dir
copy_to_output_dir --subfolder "nuget"

info_log "All nuget packages successfully built"
fi

if [[ "${CONTAINER_BUILD}" == "true" ]]; then
info_log "Building container image..."
build_app --project "${APP_PROJECT}"
copy_to_output_dir --subfolder "app"
local _annotation_config=""
[[ -n "${ANNOTATION_CONFIG}" ]] && _annotation_config="--annotation-config ${ANNOTATION_CONFIG}"
run_a_script "${SPACEFX_DIR}/build/build_containerImage.sh \
--dockerfile ${SPACEFX_DIR}/build/dotnet/Dockerfile.svc-base \
--image-tag ${APP_VERSION} \
--add-base-suffix \
--no-spacefx-dev \
--architecture ${ARCHITECTURE} \
--repo-dir ${OUTPUT_DIR}/app \
--app-name ${APP_NAME} ${_annotation_config}"

run_a_script "${SPACEFX_DIR}/build/build_containerImage.sh \
--dockerfile ${SPACEFX_DIR}/build/dotnet/Dockerfile.svc-base \
--image-tag ${APP_VERSION} \
--no-spacefx-dev \
--architecture ${ARCHITECTURE} \
--repo-dir ${OUTPUT_DIR}/app \
--app-name ${APP_NAME} ${_annotation_config}"

info_log "...successfully built container image"
fi



info_log "------------------------------------------"
info_log "END: ${SCRIPT_NAME}"

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-hostsvc-link
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-hostsvc-logging
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-hostsvc-position
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-hostsvc-sensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-platform-deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-platform-mts
3 changes: 3 additions & 0 deletions config/github/annotations/azure-orbital-space-sdk-vth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config:
annotations:
- annotation: org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-vth
4 changes: 2 additions & 2 deletions scripts/stage_spacefx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function show_help() {
echo "options:"
echo "--architecture | -a [OPTIONAL] Change the target architecture for download (defaults to current architecture)"
echo "--dev-environment | -d [OPTIONAL] Stage the environment for development."
echo "--build-artifact [OPTIONAL] Add a build artifact to download and stage. Must have match in buildartifacts.json. Can be passed multiple times"
echo "--artifact [OPTIONAL] Add a build artifact to download and stage. Must have match in buildartifacts.json. Can be passed multiple times"
echo "--container | -c [OPTIONAL] name of the container to pull. Can be passed multiple times"
echo "--nvidia-gpu-plugin | -n [OPTIONAL] Include the nvidia gpu plugin (+325 MB)"
echo "--help | -h [OPTIONAL] Help script (this screen)"
Expand Down Expand Up @@ -69,7 +69,7 @@ while [[ "$#" -gt 0 ]]; do
shift
CONTAINERS+=("$1")
;;
--build-artifact)
--artifact)
shift
BUILD_ARTIFACTS+=("$1")
;;
Expand Down

0 comments on commit b9297c4

Please sign in to comment.