-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add devcontainer scripts on create and post start (#5)
- Loading branch information
Showing
6 changed files
with
151 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
"files": [ | ||
".pre-commit-config.yaml", | ||
".project-creation/templates/.devcontainer/devcontainer.json", | ||
".project-creation/templates/.vscode/launch.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
components/extensions/devcontainer-setup-java/src/.devcontainer/scripts/onCreateCommand.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License, Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# exit when any command fails | ||
set -e | ||
|
||
# restart Docker connection if in Codespaces | ||
# Workaround according to https://github.com/devcontainers/features/issues/671#issuecomment-1701754897 | ||
if [ "${CODESPACES}" = "true" ]; then | ||
sudo pkill dockerd && sudo pkill containerd | ||
/usr/local/share/docker-init.sh | ||
fi | ||
|
||
echo "#######################################################" | ||
echo "### Run VADF Lifecycle Management ###" | ||
echo "#######################################################" | ||
# needed to get rid of old leftovers | ||
sudo rm -rf ~/.velocitas | ||
velocitas init | ||
velocitas sync | ||
|
||
sudo chmod +x .devcontainer/scripts/*.sh | ||
sudo chown -R $(whoami) $HOME | ||
|
||
if [ "${CODESPACES}" = "true" ]; then | ||
echo "#######################################################" | ||
echo "### Setup Access to Codespaces ###" | ||
echo "#######################################################" | ||
|
||
# Remove the default credential helper | ||
sudo sed -i -E 's/helper =.*//' /etc/gitconfig | ||
|
||
# Add one that just uses secrets available in the Codespace | ||
git config --global credential.helper '!f() { sleep 1; echo "username=${GITHUB_USER}"; echo "password=${MY_GH_TOKEN}"; }; f' | ||
fi | ||
|
||
git config --global --add safe.directory "*" | ||
|
||
echo "#######################################################" | ||
echo "### Install Dependencies ###" | ||
echo "#######################################################" | ||
velocitas exec build-system install | ||
|
||
echo "#######################################################" | ||
echo "### VADF package status ###" | ||
echo "#######################################################" | ||
velocitas upgrade --dry-run | ||
|
||
# Don't let container creation fail if lifecycle management fails | ||
echo "Done!" |
80 changes: 80 additions & 0 deletions
80
components/extensions/devcontainer-setup-java/src/.devcontainer/scripts/postStartCommand.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License, Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
echo "#######################################################" | ||
echo "### Auto-Upgrade CLI ###" | ||
echo "#######################################################" | ||
|
||
ROOT_DIRECTORY=$( realpath "$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/../.." ) | ||
DESIRED_VERSION=$(cat $ROOT_DIRECTORY/.velocitas.json | jq .cliVersion | tr -d '"') | ||
|
||
# Get installed CLI version | ||
INSTALLED_VERSION=v$(velocitas --version | sed -E 's/velocitas-cli\/(\w+.\w+.\w+).*/\1/') | ||
|
||
if [ "$DESIRED_VERSION" = "$INSTALLED_VERSION" ]; then | ||
echo "> Already up to date!" | ||
exit 0 | ||
else | ||
echo "> Checking upgrade to $DESIRED_VERSION" | ||
fi | ||
|
||
AUTHORIZATION_HEADER="" | ||
if [ "${GITHUB_API_TOKEN}" != "" ]; then | ||
AUTHORIZATION_HEADER="-H \"Authorization: Bearer ${GITHUB_API_TOKEN}\"" | ||
fi | ||
|
||
if [ "$DESIRED_VERSION" = "latest" ]; then | ||
CLI_RELEASES_URL=https://api.github.com/repos/eclipse-velocitas/cli/releases/latest | ||
else | ||
CLI_RELEASES_URL=https://api.github.com/repos/eclipse-velocitas/cli/releases/tags/${DESIRED_VERSION} | ||
fi | ||
|
||
CLI_RELEASES=$(curl -s -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
${AUTHORIZATION_HEADER} \ | ||
${CLI_RELEASES_URL}) | ||
|
||
res=$? | ||
if test "$res" != "0"; then | ||
echo "the curl command failed with exit code: $res" | ||
exit 0 | ||
fi | ||
|
||
DESIRED_VERSION_TAG=$(echo ${CLI_RELEASES} | jq -r .name) | ||
|
||
if [ "$DESIRED_VERSION_TAG" = "null" ] || [ "$DESIRED_VERSION_TAG" = "" ]; then | ||
echo "> Can't find desired Velocitas CLI version: $DESIRED_VERSION. Skipping Auto-Upgrade." | ||
exit 0 | ||
fi | ||
|
||
if [ "$DESIRED_VERSION_TAG" != "$INSTALLED_VERSION" ]; then | ||
echo "> Upgrading CLI..." | ||
if [[ $(arch) == "aarch64" ]]; then | ||
CLI_ASSET_NAME=velocitas-linux-arm64 | ||
else | ||
CLI_ASSET_NAME=velocitas-linux-x64 | ||
fi | ||
CLI_INSTALL_PATH=/usr/bin/velocitas | ||
CLI_DOWNLOAD_URL="https://github.com/eclipse-velocitas/cli/releases/download/${DESIRED_VERSION_TAG}/${CLI_ASSET_NAME}" | ||
|
||
echo "> Downloading Velocitas CLI from ${CLI_DOWNLOAD_URL}" | ||
sudo curl -s -L ${CLI_DOWNLOAD_URL} -o "${CLI_INSTALL_PATH}" | ||
sudo chmod +x "${CLI_INSTALL_PATH}" | ||
else | ||
echo "> Up to date!" | ||
fi | ||
|
||
echo "> Using CLI: $(velocitas --version)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters