Skip to content

Commit

Permalink
First implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaloGithub authored Mar 21, 2022
1 parent c73e3e9 commit 8a9469c
Show file tree
Hide file tree
Showing 12 changed files with 550 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

on:
push:
branches:
- main

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run shellcheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: --external-sources

plugin_test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: openresty -v

git_tag:
runs-on: ubuntu-latest
steps:
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
needs:
- shellcheck
- plugin_test
60 changes: 60 additions & 0 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Debug

on:
push:
branches-ignore:
- main

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run shellcheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: --external-sources

plugin_test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
# # Uncomment below steps for debugging in build machine:
# - uses: actions/checkout@v3
# with:
# repository: asdf-vm/asdf
# path: asdf
#
# - uses: actions/checkout@v3
# with:
# path: asdf-openresty
#
# # Run below command after SSH into build machine:
# # ```shell
# # ./asdf/bin/asdf plugin-test openresty ./asdf-openresty/ --asdf-tool-version latest openresty -v
# # ```
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1

- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: openresty -v

git_tag:
runs-on: ubuntu-latest
steps:
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true
needs:
- shellcheck
- plugin_test
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
asdf-openresty
==============

[OpenResty](https://openresty.org/en/) plugin for [asdf](https://github.com/asdf-vm/asdf) version manager.

## Install

```shell
asdf plugin-add openresty https://github.com/HaloGithub/asdf-openresty.git
```

## Linting

```shell
docker run --rm -v $(pwd):/mnt koalaman/shellcheck --format=gcc --external-sources bin/* lib/**/*.bash
```
28 changes: 28 additions & 0 deletions bin/download
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -euo pipefail


if [ "${#BASH_SOURCE[@]}" -gt 0 ]; then
current_script_path="${BASH_SOURCE[0]}"
else
current_script_path="$0"
fi
current_script_dir="$(dirname "$current_script_path")"
# shellcheck source=lib/distro/main.bash
source "$current_script_dir/../lib/distro/main.bash"

plugin_dir=$(realpath "$(dirname "$current_script_dir")")


# shellcheck source=lib/utils.bash
source "$plugin_dir/lib/utils.bash"


(
mkdir -p "$ASDF_DOWNLOAD_PATH"
download_openssl "$ASDF_DOWNLOAD_PATH"
download_pcre "$ASDF_DOWNLOAD_PATH"
download_openresty "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_VERSION"
download_luarocks "$ASDF_DOWNLOAD_PATH"
) || (rm -rf "$ASDF_DOWNLOAD_PATH"; exit 1)
35 changes: 35 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail


if [ "${#BASH_SOURCE[@]}" -gt 0 ]; then
current_script_path="${BASH_SOURCE[0]}"
else
current_script_path="$0"
fi
current_script_dir="$(dirname "$current_script_path")"
# shellcheck source=lib/distro/main.bash
source "$current_script_dir/../lib/distro/main.bash"
os_init

plugin_dir=$(realpath "$(dirname "$current_script_dir")")


# shellcheck source=lib/utils.bash
source "$plugin_dir/lib/utils.bash"


if [ "$ASDF_INSTALL_TYPE" != "version" ]; then
fail "Support 'version' install_type only."
fi


(
# install_openssl "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_PATH" "$ASDF_CONCURRENCY"
# install_pcre "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_PATH" "$ASDF_CONCURRENCY"
install_openresty "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_PATH" "$ASDF_CONCURRENCY" "$ASDF_INSTALL_VERSION"
install_luarocks "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_PATH" "$ASDF_CONCURRENCY"

os_post_make
) || (rm -rf "$ASDF_INSTALL_PATH"; exit 1)
22 changes: 22 additions & 0 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euo pipefail


if [ "${#BASH_SOURCE[@]}" -gt 0 ]; then
current_script_path="${BASH_SOURCE[0]}"
else
current_script_path="$0"
fi
current_script_dir="$(dirname "$current_script_path")"
# shellcheck source=lib/distro/main.bash
source "$current_script_dir/../lib/distro/main.bash"

plugin_dir=$(realpath "$(dirname "$current_script_dir")")


# shellcheck source=lib/utils.bash
source "$plugin_dir/lib/utils.bash"


list_github_tags | sort_versions | xargs echo
3 changes: 3 additions & 0 deletions bin/list-bin-paths
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo -n "openresty/bin openresty/luajit/bin openresty/nginx/sbin luarocks/bin"
47 changes: 47 additions & 0 deletions lib/distro/darwin/default.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -euo pipefail

os_init() {
# Remove below options for MacOS:
# 1. --with-file-aio: Due to "no supported file AIO was found" error
export RESTY_CONFIG_OPTIONS="\
--with-compat \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-http_xslt_module=dynamic \
--with-ipv6 \
--with-mail \
--with-mail_ssl_module \
--with-md5-asm \
--with-pcre-jit \
--with-sha1-asm \
--with-stream \
--with-stream_ssl_module \
--with-threads \
"
brew install libgeoip
}


os_post_make() {
# Copy from https://github.com/openresty/docker-openresty/blob/master/focal/Dockerfile#L161
if [ -n "$RESTY_EVAL_POST_MAKE" ]; then
eval "$RESTY_EVAL_POST_MAKE";
fi
}
59 changes: 59 additions & 0 deletions lib/distro/main.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -euo pipefail


if [ "${#BASH_SOURCE[@]}" -gt 0 ]; then
main_script_path="${BASH_SOURCE[0]}"
else
main_script_path="$0"
fi
main_script_dir="$(dirname "$main_script_path")"


fail() {
echo -e "asdf-openresty: $*"
exit 1
}


get_os_distro() {
lsb_release -i | sed 's/Distributor ID:\s*//' | tr '[:upper:]' '[:lower:]'
}


get_os_code() {
lsb_release -c | sed 's/Codename:\s*//'
}


uname=$(uname)
case "$uname" in
(*Linux*)
# shellcheck source=lib/vars.bash
source "$main_script_dir/../vars.bash"

case $(get_os_distro) in
ubuntu)
# shellcheck source=lib/distro/ubuntu/default.bash
source "$main_script_dir/ubuntu/default.bash"
;;
*)
fail "Unsupported os distro: $(get_os_distro)"
;;
esac
;;
(*Darwin*)
brew install coreutils

# shellcheck source=lib/vars.bash
source "$main_script_dir/../vars.bash"

# shellcheck source=lib/distro/darwin/default.bash
source "$main_script_dir/darwin/default.bash"
;;
(*)
fail "Unsupported platform: $uname"
exit 2
;;
esac;
41 changes: 41 additions & 0 deletions lib/distro/ubuntu/default.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -euo pipefail

os_init() {
# Copy from https://github.com/openresty/docker-openresty/blob/master/focal/Dockerfile#L85-L102
DEBIAN_FRONTEND=noninteractive sudo apt-get update \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
gettext-base \
libgd-dev \
libgeoip-dev \
libncurses5-dev \
libperl-dev \
libreadline-dev \
libxslt1-dev \
make \
perl \
unzip \
zlib1g-dev \
"$RESTY_ADD_PACKAGE_BUILDDEPS" \
"$RESTY_ADD_PACKAGE_RUNDEPS"
}


os_post_make() {
# Copy from https://github.com/openresty/docker-openresty/blob/master/focal/Dockerfile#L161
if [ -n "$RESTY_EVAL_POST_MAKE" ]; then
eval "$RESTY_EVAL_POST_MAKE"
fi

# Copy from https://github.com/openresty/docker-openresty/blob/master/focal/Dockerfile#L163
if [ -n "$RESTY_ADD_PACKAGE_BUILDDEPS" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get remove -y --purge "$RESTY_ADD_PACKAGE_BUILDDEPS"
fi

# Copy from https://github.com/openresty/docker-openresty/blob/master/focal/Dockerfile#L164
DEBIAN_FRONTEND=noninteractive sudo apt-get autoremove -y
}
Loading

0 comments on commit 8a9469c

Please sign in to comment.