@ -2,6 +2,21 @@
BOLD = '\033[0;1m'
BOLD = '\033[0;1m'
not_configured( ) {
type = $1
echo " 🤔 no $type repository is set, skipping $type configuration. "
echo " You can configure a $type repository by providing a key for ' $type ' in the 'package_managers' input. "
}
config_complete( ) {
echo "🥳 Configuration complete!"
}
register_docker( ) {
repo = $1
echo -n " ${ ARTIFACTORY_ACCESS_TOKEN } " | docker login " $repo " --username ${ ARTIFACTORY_USERNAME } --password-stdin
}
# check if JFrog CLI is already installed
# check if JFrog CLI is already installed
if command -v jf > /dev/null 2>& 1; then
if command -v jf > /dev/null 2>& 1; then
echo "✅ JFrog CLI is already installed, skipping installation."
echo "✅ JFrog CLI is already installed, skipping installation."
@ -11,8 +26,7 @@ else
sudo chmod 755 /usr/local/bin/jf
sudo chmod 755 /usr/local/bin/jf
fi
fi
# The jf CLI checks $CI when determining whether to use interactive
# The jf CLI checks $CI when determining whether to use interactive flows.
# flows.
export CI = true
export CI = true
# Authenticate JFrog CLI with Artifactory.
# Authenticate JFrog CLI with Artifactory.
echo " ${ ARTIFACTORY_ACCESS_TOKEN } " | jf c add --access-token-stdin --url " ${ JFROG_URL } " --overwrite " ${ JFROG_SERVER_ID } "
echo " ${ ARTIFACTORY_ACCESS_TOKEN } " | jf c add --access-token-stdin --url " ${ JFROG_URL } " --overwrite " ${ JFROG_SERVER_ID } "
@ -20,52 +34,47 @@ echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFRO
jf c use " ${ JFROG_SERVER_ID } "
jf c use " ${ JFROG_SERVER_ID } "
# Configure npm to use the Artifactory "npm" repository.
# Configure npm to use the Artifactory "npm" repository.
if [ -z " ${ REPOSITORY_NPM } " ] ; then
if [ -z " ${ HAS_NPM } " ] ; then
echo "🤔 no npm repository is set, skipping npm configuration."
not_configured npm
echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input."
else
else
echo "📦 Configuring npm..."
echo "📦 Configuring npm..."
jf npmc --global --repo-resolve " ${ REPOSITORY_NPM } "
jf npmc --global --repo-resolve " ${ REPOSITORY_NPM } "
cat << EOF > ~/.npmrc
cat << EOF > ~/.npmrc
email = ${ ARTIFACTORY_EMAIL }
${ NPMRC }
registry = ${ JFROG_URL } /artifactory/api/npm/${ REPOSITORY_NPM }
EOF
EOF
echo " // ${ JFROG_HOST } /artifactory/api/npm/ ${ REPOSITORY_NPM } /:_authToken= ${ ARTIFACTORY_ACCESS_TOKEN } " >> ~/.npmrc
config_complete
fi
fi
# Configure the `pip` to use the Artifactory "python" repository.
# Configure the `pip` to use the Artifactory "python" repository.
if [ -z " ${ REPOSITORY_PYPI } " ] ; then
if [ -z " ${ HAS_PYPI } " ] ; then
echo "🤔 no pypi repository is set, skipping pip configuration."
not_configured pypi
echo "You can configure a pypi repository by providing the a key for 'pypi' in the 'package_managers' input."
else
else
echo "🐍 Configuring pip..."
echo "🐍 Configuring pip..."
jf pipc --global --repo-resolve " ${ REPOSITORY_PYPI } "
jf pipc --global --repo-resolve " ${ REPOSITORY_PYPI } "
mkdir -p ~/.pip
mkdir -p ~/.pip
cat << EOF > ~/.pip/pip.conf
cat << EOF > ~/.pip/pip.conf
[ global]
${ PIP_CONF }
index-url = https://${ ARTIFACTORY_USERNAME } :${ ARTIFACTORY_ACCESS_TOKEN } @${ JFROG_HOST } /artifactory/api/pypi/${ REPOSITORY_PYPI } /simple
EOF
EOF
config_complete
fi
fi
# Configure Artifactory "go" repository.
# Configure Artifactory "go" repository.
if [ -z " ${ REPOSITORY_GO } " ] ; then
if [ -z " ${ HAS_GO } " ] ; then
echo "🤔 no go repository is set, skipping go configuration."
not_configured go
echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input."
else
else
echo "🐹 Configuring go..."
echo "🐹 Configuring go..."
jf goc --global --repo-resolve " ${ REPOSITORY_GO } "
jf goc --global --repo-resolve " ${ REPOSITORY_GO } "
config_complete
fi
fi
echo "🥳 Configuration complete!"
# Configure the JFrog CLI to use the Artifactory "docker" repository.
# Configure the JFrog CLI to use the Artifactory "docker" repository.
if [ -z " ${ REPOSITORY_DOCKER } " ] ; then
if [ -z " ${ HAS_DOCKER } " ] ; then
echo "🤔 no docker repository is set, skipping docker configuration."
not_configured docker
echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input."
else
else
if command -v docker > /dev/null 2>& 1; then
if command -v docker > /dev/null 2>& 1; then
echo "🔑 Configuring 🐳 docker credentials..."
echo "🔑 Configuring 🐳 docker credentials..."
mkdir -p ~/.docker
mkdir -p ~/.docker
echo -n " ${ ARTIFACTORY_ACCESS_TOKEN } " | docker login ${ JFROG_HOST } --username ${ ARTIFACTORY_USERNAME } --password-stdin
${ REGISTER_DOCKER }
else
else
echo "🤔 no docker is installed, skipping docker configuration."
echo "🤔 no docker is installed, skipping docker configuration."
fi
fi
@ -96,20 +105,19 @@ echo "📦 Configuring JFrog CLI completion..."
SHELLNAME = $( grep " ^ $USER " /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}' )
SHELLNAME = $( grep " ^ $USER " /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}' )
# Generate the completion script
# Generate the completion script
jf completion $SHELLNAME --install
jf completion $SHELLNAME --install
begin_stanza = "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)"
# Add the completion script to the user's shell profile
# Add the completion script to the user's shell profile
if [ " $SHELLNAME " = = "bash" ] && [ -f ~/.bashrc ] ; then
if [ " $SHELLNAME " = = "bash" ] && [ -f ~/.bashrc ] ; then
if ! grep -q "# jf CLI shell completion" ~/.bashrc; then
if ! grep -q " $begin_stanza " ~/.bashrc; then
echo "" >> ~/.bashrc
printf "%s\n" " $begin_stanza " >> ~/.bashrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc
echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc
echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc
echo "# END: jf CLI shell completion" >> ~/.bashrc
echo "# END: jf CLI shell completion" >> ~/.bashrc
else
else
echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping."
echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping."
fi
fi
elif [ " $SHELLNAME " = = "zsh" ] && [ -f ~/.zshrc ] ; then
elif [ " $SHELLNAME " = = "zsh" ] && [ -f ~/.zshrc ] ; then
if ! grep -q "# jf CLI shell completion" ~/.zshrc; then
if ! grep -q " $begin_stanza " ~/.zshrc; then
echo "" >> ~/.zshrc
printf "\n%s\n" " $begin_stanza " >> ~/.zshrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.zshrc
echo "autoload -Uz compinit" >> ~/.zshrc
echo "autoload -Uz compinit" >> ~/.zshrc
echo "compinit" >> ~/.zshrc
echo "compinit" >> ~/.zshrc
echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc
echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc