-
Notifications
You must be signed in to change notification settings - Fork 58
feat(jfrog): add JFrog vscode extension, CLI completion and docker support #115
Changes from 50 commits
0421dfe
cb49f8d
85e9297
902b382
cf60e20
68cbcd1
44f9a1e
5127897
97a6613
c6d8f39
eea0274
e36c284
d36b580
4a0fd4c
7f9a6bc
f621777
ee43370
955eadb
9cc2a37
c0c8ac5
7b9302e
cbd294d
5694858
b1f2cc7
489fcd1
5b1337e
963d4d6
c289810
7d85783
168e20d
6689114
04c2bcb
f5a7310
268bfe4
ac9afb2
cd27883
740b3fe
e85607f
d9a25fa
5d54492
a9baa1f
3308bf1
b1e182f
f2ebcf0
b53e2d8
171fb35
fee0d4e
236e4ac
7362993
1738ff1
3b96d21
1cfefb8
22ecc79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,38 +7,38 @@ if command -v jf > /dev/null 2>&1; then | |
echo "✅ JFrog CLI is already installed, skipping installation." | ||
else | ||
echo "📦 Installing JFrog CLI..." | ||
# Install the JFrog CLI. | ||
curl -fL https://install-cli.jfrog.io | sudo sh | ||
sudo chmod 755 /usr/local/bin/jf | ||
fi | ||
|
||
# The jf CLI checks $CI when determining whether to use interactive | ||
# flows. | ||
export CI=true | ||
# Authenticate with the JFrog CLI. | ||
jf c rm 0 || true | ||
echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 | ||
# Authenticate JFrog CLI with Artifactory. | ||
echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" --overwrite 0 | ||
# Set the configured server as the default. | ||
jf c use 0 | ||
|
||
# Configure npm to use the Artifactory "npm" repository. | ||
if [ -z "${REPOSITORY_NPM}" ]; then | ||
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." | ||
echo "🤔 no npm repository is set, skipping npm configuration." | ||
echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." | ||
else | ||
# check if npm is installed and configure it to use the Artifactory "npm" repository. | ||
if command -v npm > /dev/null 2>&1; then | ||
echo "📦 Configuring npm..." | ||
jf npmc --global --repo-resolve "${REPOSITORY_NPM}" | ||
fi | ||
echo "📦 Configuring npm..." | ||
jf npmc --global --repo-resolve "${REPOSITORY_NPM}" | ||
cat << EOF > ~/.npmrc | ||
email = ${ARTIFACTORY_EMAIL} | ||
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} | ||
email=${ARTIFACTORY_EMAIL} | ||
registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} | ||
EOF | ||
jf rt curl /api/npm/auth >> ~/.npmrc | ||
echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc | ||
fi | ||
|
||
# Configure the `pip` to use the Artifactory "python" repository. | ||
if [ -z "${REPOSITORY_PYPI}" ]; then | ||
echo "🤔 REPOSITORY_PYPI is not set, skipping pip configuration." | ||
echo "🤔 no pypi repository is set, skipping pip configuration." | ||
echo "You can configure a pypi repository by providing the a key for 'pypi' in the 'package_managers' input." | ||
else | ||
echo "🐍 Configuring pip..." | ||
echo "📦 Configuring pip..." | ||
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" | ||
mkdir -p ~/.pip | ||
cat << EOF > ~/.pip/pip.conf | ||
|
@@ -47,12 +47,66 @@ index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_ | |
EOF | ||
fi | ||
|
||
# Set GOPROXY to use the Artifactory "go" repository. | ||
# Configure Artifactory "go" repository. | ||
if [ -z "${REPOSITORY_GO}" ]; then | ||
echo "🤔 REPOSITORY_GO is not set, skipping go configuration." | ||
echo "🤔 no go repository is set, skipping go configuration." | ||
echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input." | ||
else | ||
echo "🐹 Configuring go..." | ||
jf go-config --global --repo-resolve "${REPOSITORY_GO}" | ||
export GOPROXY="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/go/${REPOSITORY_GO}" | ||
jf goc --global --repo-resolve "${REPOSITORY_GO}" | ||
fi | ||
echo "🥳 Configuration complete!" | ||
|
||
# Configure the JFrog CLI to use the Artifactory "docker" repository. | ||
if [ -z "${REPOSITORY_DOCKER}" ]; then | ||
echo "🤔 no docker repository is set, skipping docker configuration." | ||
echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." | ||
else | ||
echo "🔑 Configuring 🐳 docker credentials..." | ||
mkdir -p ~/.docker | ||
echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin | ||
fi | ||
|
||
# Install the JFrog vscode extension for code-server. | ||
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then | ||
while ! [ -x /tmp/code-server/bin/code-server ]; do | ||
counter=0 | ||
if [ $counter -eq 30 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For an arbitrary timeout, this feels a bit short (slow network, hiccup, etc). It'd nice to communicate between modules since we're already assuming the path ( Also, are we sure that once this file is present, running it won't fail? Could it be incomplete (still copying), missing a resource file it requires, etc? (This also paints a case for the aforementioned suggestion.) As a perhaps better alternative, it would be pretty nice to be able to define script dependencies in the modules, e.g. code server module script runs before this one, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I agree. Having a mechanism for dependence is probably the best base. For now we can modify the code-server module to create status files. I am not sure how we can check the insatlling status. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, should we condition the part of the module or the whole module? I think your idea can be extended to have a common input for all modules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's a way to reference another modules resource, I think that would work well for this use case. But I'm not sure how terraform would behave in this case. Maybe we need both a module and a script level dependency so that terraform can exit early if only one module is used without its dependency? Or do we automatically pull in dependencies without them being explicitly declared? Anyway, as for how the script part might look, maybe something like this? // code-server
resource "coder_script" "install" {}
// my-module
resource "coder_script" "takes_a_while" {}
resource "coder_script" "finalize" {
depends_on = [code-server.coder_script.install, coder_script.takes_a_while]
} Again, if we can refer like this, it'd be ideal, otherwise we may need to use strings and define the dependency in runtime? Perhaps it would be a good idea to think about what other use-cases we have, and maybe write a proposal? This might also tie a little bit into coder/coder#11131? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the meantime, I'd rather not use status files, but instead wait for the process to be started or a successful curl or something. I do like us eventually using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now I am going to merge them without any modification until we have a formal way to resolve #93. |
||
echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." | ||
exit 1 | ||
fi | ||
echo "Waiting for /tmp/code-server/bin/code-server to be installed..." | ||
sleep 1 | ||
((counter++)) | ||
done | ||
echo "📦 Installing JFrog extension..." | ||
/tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension | ||
echo "🥳 JFrog extension installed!" | ||
else | ||
echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." | ||
fi | ||
|
||
# Configure the JFrog CLI completion | ||
echo "📦 Configuring JFrog CLI completion..." | ||
## Get the user's shell | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') | ||
## Generate the completion script | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
jf completion $SHELLNAME --install | ||
## Add the completion script to the user's shell profile | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if [ "$SHELLNAME" == "bash" ]; then | ||
if ! grep -q "# jf CLI shell completion" ~/.bashrc; then | ||
echo "" >> ~/.bashrc | ||
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc | ||
echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc | ||
echo "# END: jf CLI shell completion" >> ~/.bashrc | ||
fi | ||
elif [ "$SHELLNAME" == "zsh" ]; then | ||
if ! grep -q "# jf CLI shell completion" ~/.zshrc; then | ||
echo "" >> ~/.zshrc | ||
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.zshrc | ||
echo "autoload -Uz compinit" >> ~/.zshrc | ||
echo "compinit" >> ~/.zshrc | ||
echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc | ||
echo "# END: jf CLI shell completion" >> ~/.zshrc | ||
fi | ||
fi |
Uh oh!
There was an error while loading. Please reload this page.