Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release packages to Cloudsmith #108

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ifeq ($(GOARCH), aarch64)
endif

PHP_BINARY_PATH := internal/legacy/archives/php_$(GOOS)_$(GOARCH)
VERSION := $(shell git describe --always)

# Tooling versions
GORELEASER_VERSION=v1.20
Expand Down Expand Up @@ -80,7 +81,8 @@ clean-phar:
rm -f internal/legacy/archives/platform.phar

release: goreleaser clean-phar internal/legacy/archives/platform.phar php copy-config-file
PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser release --clean --auto-snapshot --config="$(GORELEASER_CONFIG_FILE)"
PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser release --clean --config="$(GORELEASER_CONFIG_FILE)"
VERSION=$(VERSION) bash cloudsmith.sh

.PHONY: test
test: ## Run unit tests
Expand Down
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,72 @@ The installer is configurable using the following environment variables:
curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | INSTALL_METHOD=raw INSTALL_DIR=$HOME/.local/bin bash
</details>

### Alpine

```console
sudo apk add --no-cache bash
curl -1sLf \
'https://dl.cloudsmith.io/public/platformsh/cli/setup.alpine.sh' \
| sudo -E bash
```

<details>
<summary>Manual setup</summary>

apk add --no-cache curl
curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/rsa.4F1C2AC5106DA770.key' > /etc/apk/keys/[email protected]
curl -1sLf "https://dl.cloudsmith.io/public/platformsh/cli/config.alpine.txt" >> /etc/apk/repositories
apk update

</details>

```console
# Install the CLI
apk add platformsh-cli
```

### Ubuntu/Debian

```console
apt-get update
apt-get install -y apt-transport-https curl
curl -1sLf \
'https://dl.cloudsmith.io/public/platformsh/cli/setup.deb.sh' \
| sudo -E bash
```

<details>
<summary>Manual setup</summary>

apt-get update

# Only needed for Debian
apt-get install -y debian-keyring debian-archive-keyring

apt-get install -y apt-transport-https curl gnupg
curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/gpg.6ED8A90E60ABD941.key' | gpg --dearmor >> /usr/share/keyrings/platformsh-cli-archive-keyring.gpg
# If you use an Ubuntu derivative distro, such as Linux Mint, you may need to use UBUNTU_CODENAME instead of VERSION_CODENAME below.
curl -1sLf "https://dl.cloudsmith.io/public/platformsh/cli/config.deb.txt?distro=$(. /etc/os-release && echo "$ID")&codename=$(. /etc/os-release && echo "$VERSION_CODENAME")" > /etc/apt/sources.list.d/platformsh-cli.list
apt-get update

</details>

```console
# Install the CLI
apt-get install -y platformsh-cli
```

### CentOS/RHEL/Fedora

```console
curl -1sLf \
'https://dl.cloudsmith.io/public/platformsh/cli/setup.rpm.sh' \
| sudo -E bash

# Install the CLI
yum install -y platformsh-cli
```

### Manual installation

For manual installation, you can also [download the latest binaries](https://github.com/platformsh/cli/releases/latest).
Expand All @@ -86,6 +152,24 @@ scoop update platform
curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash
```

### Alpine

```console
apk add -l platformsh-cli
```

### Ubuntu/Debian

```console
apt-get upgrade platformsh-cli
```

### CentOS/RHEL/Fedora

```console
yum upgrade -y platformsh-cli
```

## Under the hood

The New Platform.sh CLI is built with backwards compatibility in mind. This is why we've embedded PHP, so that all Legacy PHP CLI commands can be executed in the exact same way, making sure that nothing breaks when you switch to it.
Expand Down
11 changes: 11 additions & 0 deletions cloudsmith.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cloudsmith push deb platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_arm64.deb
cloudsmith push deb platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_amd64.deb

cloudsmith push alpine platformsh/cli/alpine/any-version dist/platformsh-cli_${VERSION}_linux_amd64.apk
cloudsmith push alpine platformsh/cli/alpine/any-version dist/platformsh-cli_${VERSION}_linux_arm64.apk

cloudsmith push rpm platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_amd64.rpm
cloudsmith push rpm platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_arm64.rpm

cloudsmith push raw platformsh/cli dist/platform_${VERSION}_linux_amd64.tar.gz --version ${VERSION}
cloudsmith push raw platformsh/cli dist/platform_${VERSION}_linux_arm64.tar.gz --version ${VERSION}
22 changes: 13 additions & 9 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ func printUpdateMessage(newRelease *internal.ReleaseInfo, cnf *config.Config) {
color.CyanString(newRelease.Version),
)

if cnf.Wrapper.HomebrewTap != "" {
executable, err := os.Executable()
if err == nil && isUnderHomebrew(executable) {
fmt.Fprintf(
color.Error,
"To upgrade, run: brew update && brew upgrade %s\n",
color.YellowString(cnf.Wrapper.HomebrewTap),
)
}
executable, err := os.Executable()
if err == nil && cnf.Wrapper.HomebrewTap != "" && isUnderHomebrew(executable) {
fmt.Fprintf(
color.Error,
"To upgrade, run: brew update && brew upgrade %s\n",
color.YellowString(cnf.Wrapper.HomebrewTap),
)
} else if cnf.Wrapper.GitHubRepo != "" {
fmt.Fprintf(
color.Error,
"To upgrade, follow the instructions at: https://github.com/%s#upgrade\n",
cnf.Wrapper.GitHubRepo,
)
}

fmt.Fprintf(color.Error, "%s\n\n", color.YellowString(newRelease.URL))
Expand Down
99 changes: 95 additions & 4 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ set -euo pipefail
# GitHub token check
: "${GITHUB_TOKEN:=}"

# CI specifics
: "${CI:=}"
: "${BUILD_NUMBER:=}"
: "${RUN_ID:=}"

# global variables
binary="platform"
cmd_shasum=""
Expand Down Expand Up @@ -178,7 +183,7 @@ function check_gzip() {

function check_version() {
if [ -z "${VERSION}" ]; then
version=$(github_curl https://api.github.com/repos/platformsh/cli/releases/latest | sed -n 's/.*"tag_name":.\?"\([^"]*\)".*/\1/p')
version=$(curl -I https://github.com/platformsh/cli/releases/latest 2>/dev/null | awk -F/ -v RS='\r\n' '/platformsh.cli.releases.tag/ {printf "%s", $NF}')
output " [*] No version specified, using latest ($version)" "success"
else
output " [*] Version ${VERSION} specified" "success"
Expand Down Expand Up @@ -234,7 +239,19 @@ function check_architecture() {
function check_install_method() {
if [ "linux" = "$kernel" ]; then
if [ -z "${INSTALL_METHOD}" ]; then
INSTALL_METHOD="raw"
if is_ci; then
INSTALL_METHOD="raw"
elif [ ! -z $VERSION ]; then
INSTALL_METHOD="raw"
elif command -v apt-get > /dev/null 2>&1; then
INSTALL_METHOD="apt"
elif command -v yum > /dev/null 2>&1; then
INSTALL_METHOD="yum"
elif command -v apk > /dev/null 2>&1; then
INSTALL_METHOD="apk"
else
INSTALL_METHOD="raw"
fi
fi
elif [ "darwin" == $kernel ]; then
if [ -z "${INSTALL_METHOD}" ]; then
Expand Down Expand Up @@ -356,13 +373,13 @@ function check_directories() {
}

function install_platformsh_homebrew() {
output "\nInstalling Platform.sh brew tap" "heading"
output "\nInstalling the Platform.sh brew tap" "heading"
if ! call_user "brew tap ${BREW_TAP}"; then
output " could not add tap to brew" "error"
exit_with_error
fi

output "\nInstalling Platform.sh CLI formula" "heading"
output "\nInstalling the Platform.sh CLI formula" "heading"

# running on Rosetta2?
arch=''
Expand All @@ -378,6 +395,60 @@ function install_platformsh_homebrew() {
fi
}

function install_platformsh_yum() {
output "\nSetting up the Platform.sh CLI yum repository" "heading"

call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.rpm.sh' > /tmp/setup.rpm.sh"

if ! call_root "bash -E /tmp/setup.rpm.sh"; then
output " could not setup the RPM repository the CLI" "error"
exit_with_error
fi

output "\nInstalling the Platform.sh CLI" "heading"

if ! call_root "yum install -y platformsh-cli"; then
output " could not install the CLI" "error"
exit_with_error
fi
}

function install_platformsh_apt() {
output "\nSetting up the Platform.sh CLI apt repository" "heading"

call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.deb.sh' > /tmp/setup.deb.sh"

if ! call_root "bash -E /tmp/setup.deb.sh"; then
output " could not setup the APT repository the CLI" "error"
exit_with_error
fi

output "\nInstalling the Platform.sh CLI" "heading"

if ! call_root "apt-get install -y platformsh-cli"; then
output " could not install the CLI" "error"
exit_with_error
fi
}

function install_platformsh_apk() {
output "\nSetting up the Platform.sh CLI apk repository" "heading"

call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.alpine.sh' > /tmp/setup.alpine.sh"

if ! call_root "bash -E /tmp/setup.alpine.sh"; then
output " could not setup the APK repository the CLI" "error"
exit_with_error
fi

output "\nInstalling the Platform.sh CLI" "heading"

if ! call_root "apk add platformsh-cli --update-cache"; then
output " could not install the CLI" "error"
exit_with_error
fi
}

function github_curl {
if [ -z "${GITHUB_TOKEN}" ]; then
curl -fsSL -H "Accept: application/vnd.github+json" $1
Expand All @@ -388,6 +459,18 @@ function github_curl {
fi
}

function is_ci {
if [ ! -z "${CI}" ]; then # GitHub Actions, Travis CI, CircleCI, Cirrus CI, GitLab CI, AppVeyor, CodeShip, dsari
return 0
elif [ ! -z "${BUILD_NUMBER}" ]; then # Jenkins, TeamCity
return 0
elif [ ! -z "${RUN_ID}" ]; then # TaskCluster, dsari
return 0
else
return 1
fi
}

function install_platformsh_raw() {
# Start downloading the right version
output "\nDownloading the Platform.sh CLI" "heading"
Expand Down Expand Up @@ -420,6 +503,12 @@ function install_platformsh_raw() {
function install_platformsh() {
if [ "homebrew" = "${INSTALL_METHOD}" ]; then
install_platformsh_homebrew
elif [ "yum" = "${INSTALL_METHOD}" ]; then
install_platformsh_yum
elif [ "apt" = "${INSTALL_METHOD}" ]; then
install_platformsh_apt
elif [ "apk" = "${INSTALL_METHOD}" ]; then
install_platformsh_apk
elif [ "raw" = "${INSTALL_METHOD}" ]; then
install_platformsh_raw
fi
Expand All @@ -437,6 +526,8 @@ if [ "raw" = "${INSTALL_METHOD}" ]; then
check_gzip
check_shasum
check_directories
elif [ "apt" = "${INSTALL_METHOD}" ] || [ "yum" = "${INSTALL_METHOD}" ] || [ "apk" = "${INSTALL_METHOD}" ]; then
check_curl
fi
install_platformsh
outro