mirror of
https://github.com/coder/coder.git
synced 2025-07-29 10:35:52 +00:00
refactor: refactor JFrog docs and template (#11336)
This commit is contained in:
committed by
GitHub
parent
5a558b69c3
commit
0ebd656cd1
@@ -41,33 +41,35 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
coder = {
|
coder = {
|
||||||
source = "coder/coder"
|
source = "coder/coder"
|
||||||
version = "~> 0.11.1"
|
|
||||||
}
|
}
|
||||||
docker = {
|
docker = {
|
||||||
source = "kreuzwerker/docker"
|
source = "kreuzwerker/docker"
|
||||||
version = "~> 3.0.1"
|
|
||||||
}
|
}
|
||||||
artifactory = {
|
artifactory = {
|
||||||
source = "registry.terraform.io/jfrog/artifactory"
|
source = "registry.terraform.io/jfrog/artifactory"
|
||||||
version = "~> 8.4.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "jfrog_host" {
|
variable "jfrog_url" {
|
||||||
type = string
|
type = string
|
||||||
description = "JFrog instance hostname. e.g. YYY.jfrog.io"
|
description = "JFrog instance URL. e.g. https://jfrog.example.com"
|
||||||
|
# validate the URL to ensure it starts with https:// or http://
|
||||||
|
validation {
|
||||||
|
condition = can(regex("^https?://", var.jfrog_url))
|
||||||
|
error_message = "JFrog URL must start with https:// or http://"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "artifactory_access_token" {
|
variable "artifactory_admin_access_token" {
|
||||||
type = string
|
type = string
|
||||||
description = "The admin-level access token to use for JFrog."
|
description = "The admin-level access token to use for JFrog with scope applied-permissions/admin"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configure the Artifactory provider
|
# Configure the Artifactory provider
|
||||||
provider "artifactory" {
|
provider "artifactory" {
|
||||||
url = "https://${var.jfrog_host}/artifactory"
|
url = "${var.jfrog_url}/artifactory"
|
||||||
access_token = "${var.artifactory_access_token}"
|
access_token = "${var.artifactory_admin_access_token}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "artifactory_scoped_token" "me" {
|
resource "artifactory_scoped_token" "me" {
|
||||||
@@ -80,7 +82,7 @@ resource "artifactory_scoped_token" "me" {
|
|||||||
When pushing the template, you can pass in the variables using the `--var` flag:
|
When pushing the template, you can pass in the variables using the `--var` flag:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
coder templates push --var 'jfrog_host=YYY.jfrog.io' --var 'artifactory_access_token=XXX'
|
coder templates push --var 'jfrog_url=https://YYY.jfrog.io' --var 'artifactory_admin_access_token=XXX'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installing JFrog CLI
|
## Installing JFrog CLI
|
||||||
@@ -118,6 +120,10 @@ locals {
|
|||||||
python = "pypi"
|
python = "pypi"
|
||||||
go = "go"
|
go = "go"
|
||||||
}
|
}
|
||||||
|
# Make sure to use the same field as the username field in the Artifactory
|
||||||
|
# It can be either the username or the email address.
|
||||||
|
artifactory_username = data.coder_workspace.me.owner_email
|
||||||
|
jfrog_host = replace(var.jfrog_url, "^https://", "")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -133,7 +139,7 @@ resource "coder_agent" "main" {
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# install and start code-server
|
# install and start code-server
|
||||||
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
|
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server
|
||||||
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
||||||
|
|
||||||
# The jf CLI checks $CI when determining whether to use interactive
|
# The jf CLI checks $CI when determining whether to use interactive
|
||||||
@@ -142,12 +148,12 @@ resource "coder_agent" "main" {
|
|||||||
|
|
||||||
jf c rm 0 || true
|
jf c rm 0 || true
|
||||||
echo ${artifactory_scoped_token.me.access_token} | \
|
echo ${artifactory_scoped_token.me.access_token} | \
|
||||||
jf c add --access-token-stdin --url https://${var.jfrog_host} 0
|
jf c add --access-token-stdin --url ${var.jfrog_url} 0
|
||||||
|
|
||||||
# Configure the `npm` CLI to use the Artifactory "npm" repository.
|
# Configure the `npm` CLI to use the Artifactory "npm" repository.
|
||||||
cat << EOF > ~/.npmrc
|
cat << EOF > ~/.npmrc
|
||||||
email = ${data.coder_workspace.me.owner_email}
|
email = ${data.coder_workspace.me.owner_email}
|
||||||
registry = https://${var.jfrog_host}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
|
registry = ${var.jfrog_url}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
|
||||||
EOF
|
EOF
|
||||||
jf rt curl /api/npm/auth >> .npmrc
|
jf rt curl /api/npm/auth >> .npmrc
|
||||||
|
|
||||||
@@ -155,13 +161,13 @@ resource "coder_agent" "main" {
|
|||||||
mkdir -p ~/.pip
|
mkdir -p ~/.pip
|
||||||
cat << EOF > ~/.pip/pip.conf
|
cat << EOF > ~/.pip/pip.conf
|
||||||
[global]
|
[global]
|
||||||
index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
|
index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
# Set GOPROXY to use the Artifactory "go" repository.
|
# Set GOPROXY to use the Artifactory "go" repository.
|
||||||
env = {
|
env = {
|
||||||
GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
|
GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local..jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -192,9 +198,7 @@ following lines into your `startup_script`:
|
|||||||
# Install the JFrog VS Code extension.
|
# Install the JFrog VS Code extension.
|
||||||
# Find the latest version number at
|
# Find the latest version number at
|
||||||
# https://open-vsx.org/extension/JFrog/jfrog-vscode-extension.
|
# https://open-vsx.org/extension/JFrog/jfrog-vscode-extension.
|
||||||
JFROG_EXT_VERSION=2.4.1
|
/tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension
|
||||||
curl -o /tmp/jfrog.vsix -L "https://open-vsx.org/api/JFrog/jfrog-vscode-extension/$JFROG_EXT_VERSION/file/JFrog.jfrog-vscode-extension-$JFROG_EXT_VERSION.vsix"
|
|
||||||
/tmp/code-server/bin/code-server --install-extension /tmp/jfrog.vsix
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that this method will only work if your developers use code-server.
|
Note that this method will only work if your developers use code-server.
|
||||||
@@ -208,7 +212,7 @@ Artifactory:
|
|||||||
# Configure the `npm` CLI to use the Artifactory "npm" registry.
|
# Configure the `npm` CLI to use the Artifactory "npm" registry.
|
||||||
cat << EOF > ~/.npmrc
|
cat << EOF > ~/.npmrc
|
||||||
email = ${data.coder_workspace.me.owner_email}
|
email = ${data.coder_workspace.me.owner_email}
|
||||||
registry = https://${var.jfrog_host}/artifactory/api/npm/npm/
|
registry = ${var.jfrog_url}/artifactory/api/npm/npm/
|
||||||
EOF
|
EOF
|
||||||
jf rt curl /api/npm/auth >> .npmrc
|
jf rt curl /api/npm/auth >> .npmrc
|
||||||
```
|
```
|
||||||
@@ -227,7 +231,7 @@ Artifactory:
|
|||||||
mkdir -p ~/.pip
|
mkdir -p ~/.pip
|
||||||
cat << EOF > ~/.pip/pip.conf
|
cat << EOF > ~/.pip/pip.conf
|
||||||
[global]
|
[global]
|
||||||
index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/pypi/simple
|
index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/pypi/simple
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -243,7 +247,7 @@ Add the following environment variable to your `coder_agent` block to configure
|
|||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
env = {
|
env = {
|
||||||
GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/go"
|
GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/go"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ tags: [local, docker, jfrog]
|
|||||||
icon: /icon/docker.png
|
icon: /icon/docker.png
|
||||||
---
|
---
|
||||||
|
|
||||||
# docker
|
# Docker
|
||||||
|
|
||||||
To get started, run `coder templates init`. When prompted, select this template.
|
To get started, run `coder templates init`. When prompted, select this template.
|
||||||
Follow the on-screen instructions to proceed.
|
Follow the on-screen instructions to proceed.
|
||||||
@@ -22,5 +22,5 @@ the dashboard UI over `localhost:13337`.
|
|||||||
|
|
||||||
# Next steps
|
# Next steps
|
||||||
|
|
||||||
Check out our [Docker](../docker/) template for a more fully featured Docker
|
Check out our [Docker](../../templates/docker/) template for a more fully featured Docker
|
||||||
example.
|
example.
|
||||||
|
@@ -13,8 +13,8 @@ terraform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
# take care to use owner_email instead of owner because users can change
|
# Make sure to use the same field as the username field in the Artifactory
|
||||||
# their username.
|
# It can be either the username or the email address.
|
||||||
artifactory_username = data.coder_workspace.me.owner_email
|
artifactory_username = data.coder_workspace.me.owner_email
|
||||||
artifactory_repository_keys = {
|
artifactory_repository_keys = {
|
||||||
"npm" = "npm"
|
"npm" = "npm"
|
||||||
@@ -22,31 +22,34 @@ locals {
|
|||||||
"go" = "go"
|
"go" = "go"
|
||||||
}
|
}
|
||||||
workspace_user = data.coder_workspace.me.owner
|
workspace_user = data.coder_workspace.me.owner
|
||||||
|
jfrog_host = replace(var.jfrog_url, "^https://", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
data "coder_provisioner" "me" {
|
data "coder_provisioner" "me" {}
|
||||||
}
|
|
||||||
|
|
||||||
provider "docker" {
|
provider "docker" {}
|
||||||
}
|
|
||||||
|
|
||||||
data "coder_workspace" "me" {
|
data "coder_workspace" "me" {}
|
||||||
}
|
|
||||||
|
|
||||||
variable "jfrog_host" {
|
variable "jfrog_url" {
|
||||||
type = string
|
type = string
|
||||||
description = "JFrog instance hostname. For example, 'YYY.jfrog.io'."
|
description = "JFrog instance URL. For example, https://jfrog.example.com."
|
||||||
|
# validate the URL to ensure it starts with https:// or http://
|
||||||
|
validation {
|
||||||
|
condition = can(regex("^https?://", var.jfrog_url))
|
||||||
|
error_message = "JFrog URL must start with https:// or http://"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "artifactory_access_token" {
|
variable "artifactory_admin_access_token" {
|
||||||
type = string
|
type = string
|
||||||
description = "The admin-level access token to use for JFrog."
|
description = "The admin-level access token to use for JFrog with scope applied-permissions/admin."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configure the Artifactory provider
|
# Configure the Artifactory provider with the admin-level access token.
|
||||||
provider "artifactory" {
|
provider "artifactory" {
|
||||||
url = "https://${var.jfrog_host}/artifactory"
|
url = "${var.jfrog_url}/artifactory"
|
||||||
access_token = var.artifactory_access_token
|
access_token = var.artifactory_admin_access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "artifactory_scoped_token" "me" {
|
resource "artifactory_scoped_token" "me" {
|
||||||
@@ -63,7 +66,7 @@ resource "coder_agent" "main" {
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# install and start code-server
|
# install and start code-server
|
||||||
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
|
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server
|
||||||
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
||||||
|
|
||||||
# Install the JFrog VS Code extension.
|
# Install the JFrog VS Code extension.
|
||||||
@@ -77,12 +80,12 @@ resource "coder_agent" "main" {
|
|||||||
|
|
||||||
jf c rm 0 || true
|
jf c rm 0 || true
|
||||||
echo ${artifactory_scoped_token.me.access_token} | \
|
echo ${artifactory_scoped_token.me.access_token} | \
|
||||||
jf c add --access-token-stdin --url https://${var.jfrog_host} 0
|
jf c add --access-token-stdin --url ${var.jfrog_url} 0
|
||||||
|
|
||||||
# Configure the `npm` CLI to use the Artifactory "npm" repository.
|
# Configure the `npm` CLI to use the Artifactory "npm" repository.
|
||||||
cat << EOF > ~/.npmrc
|
cat << EOF > ~/.npmrc
|
||||||
email = ${data.coder_workspace.me.owner_email}
|
email = ${data.coder_workspace.me.owner_email}
|
||||||
registry = https://${var.jfrog_host}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
|
registry = ${var.jfrog_url}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
|
||||||
EOF
|
EOF
|
||||||
jf rt curl /api/npm/auth >> .npmrc
|
jf rt curl /api/npm/auth >> .npmrc
|
||||||
|
|
||||||
@@ -90,15 +93,15 @@ resource "coder_agent" "main" {
|
|||||||
mkdir -p ~/.pip
|
mkdir -p ~/.pip
|
||||||
cat << EOF > ~/.pip/pip.conf
|
cat << EOF > ~/.pip/pip.conf
|
||||||
[global]
|
[global]
|
||||||
index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
|
index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
# Set GOPROXY to use the Artifactory "go" repository.
|
# Set GOPROXY to use the Artifactory "go" repository.
|
||||||
env = {
|
env = {
|
||||||
GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
|
GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
|
||||||
# Authenticate with JFrog extension.
|
# Authenticate with JFrog extension.
|
||||||
JFROG_IDE_URL : "https://${var.jfrog_host}"
|
JFROG_IDE_URL : "${var.jfrog_url}"
|
||||||
JFROG_IDE_USERNAME : "${local.artifactory_username}"
|
JFROG_IDE_USERNAME : "${local.artifactory_username}"
|
||||||
JFROG_IDE_PASSWORD : "${artifactory_scoped_token.me.access_token}"
|
JFROG_IDE_PASSWORD : "${artifactory_scoped_token.me.access_token}"
|
||||||
JFROG_IDE_ACCESS_TOKEN : "${artifactory_scoped_token.me.access_token}"
|
JFROG_IDE_ACCESS_TOKEN : "${artifactory_scoped_token.me.access_token}"
|
||||||
|
Reference in New Issue
Block a user