|
1 | | -#!/usr/bin/env bash |
| 1 | +#!/bin/bash |
2 | 2 |
|
3 | | -# ------------------------------------------------------- # |
4 | | -# |
5 | | -# Skeleton for common build entry script for all elastic |
6 | | -# clients. Needs to be adapted to individual client usage. |
7 | | -# |
8 | | -# Must be called: ./.ci/make.sh <target> <params> |
9 | | -# |
10 | | -# Version: 1.1.0 |
11 | | -# |
12 | | -# Targets: |
13 | | -# --------------------------- |
14 | | -# assemble <VERSION> : build client artefacts with version |
15 | | -# bump <VERSION> : bump client internals to version |
16 | | -# codegen <VERSION> : generate endpoints |
17 | | -# docsgen <VERSION> : generate documentation |
18 | | -# examplegen : generate the doc examples |
19 | | -# clean : clean workspace |
20 | | -# |
21 | | -# ------------------------------------------------------- # |
| 3 | +set -eo pipefail |
22 | 4 |
|
23 | | -# ------------------------------------------------------- # |
24 | | -# Bootstrap |
25 | | -# ------------------------------------------------------- # |
| 5 | +BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 6 | +BASE_DIR="$( dirname "$BASE_DIR" )" |
26 | 7 |
|
27 | | -script_path=$(dirname "$(realpath -s "$0")") |
28 | | -repo=$(realpath "$script_path/../") |
29 | | - |
30 | | -# shellcheck disable=SC1090 |
31 | | -CMD=$1 |
32 | | -TASK=$1 |
33 | | -TASK_ARGS=() |
34 | | -VERSION=$2 |
35 | | -STACK_VERSION=$VERSION |
36 | | -set -euo pipefail |
37 | | - |
38 | | -product="elastic/elasticsearch-py" |
39 | | -output_folder=".ci/output" |
40 | | -codegen_folder=".ci/output" |
41 | | -OUTPUT_DIR="$repo/${output_folder}" |
42 | | -REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}" |
43 | | -mkdir -p "$OUTPUT_DIR" |
44 | | - |
45 | | -echo -e "\033[34;1mINFO:\033[0m PRODUCT ${product}\033[0m" |
46 | | -echo -e "\033[34;1mINFO:\033[0m VERSION ${STACK_VERSION}\033[0m" |
47 | | -echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m" |
48 | | - |
49 | | -# ------------------------------------------------------- # |
50 | | -# Parse Command |
51 | | -# ------------------------------------------------------- # |
52 | | - |
53 | | -case $CMD in |
54 | | - clean) |
55 | | - echo -e "\033[36;1mTARGET: clean workspace $output_folder\033[0m" |
56 | | - rm -rf "$output_folder" |
57 | | - echo -e "\033[32;1mdone.\033[0m" |
58 | | - exit 0 |
59 | | - ;; |
60 | | - assemble) |
61 | | - if [ -v $VERSION ]; then |
62 | | - echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m" |
63 | | - exit 1 |
64 | | - fi |
65 | | - echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m" |
66 | | - TASK=release |
67 | | - TASK_ARGS=("$VERSION" "$output_folder") |
68 | | - ;; |
69 | | - codegen) |
70 | | - if [ -v $VERSION ]; then |
71 | | - echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m" |
72 | | - exit 1 |
73 | | - fi |
74 | | - echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m" |
75 | | - TASK=codegen |
76 | | - # VERSION is BRANCH here for now |
77 | | - TASK_ARGS=("$VERSION" "$codegen_folder") |
78 | | - ;; |
79 | | - docsgen) |
80 | | - if [ -v $VERSION ]; then |
81 | | - echo -e "\033[31;1mTARGET: docsgen -> missing version parameter\033[0m" |
82 | | - exit 1 |
83 | | - fi |
84 | | - echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m" |
85 | | - TASK=codegen |
86 | | - # VERSION is BRANCH here for now |
87 | | - TASK_ARGS=("$VERSION" "$codegen_folder") |
88 | | - ;; |
89 | | - examplesgen) |
90 | | - echo -e "\033[36;1mTARGET: generate examples\033[0m" |
91 | | - TASK=codegen |
92 | | - # VERSION is BRANCH here for now |
93 | | - TASK_ARGS=("$VERSION" "$codegen_folder") |
94 | | - ;; |
95 | | - bump) |
96 | | - if [ -v $VERSION ]; then |
97 | | - echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m" |
98 | | - exit 1 |
99 | | - fi |
100 | | - echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m" |
101 | | - TASK=bump |
102 | | - # VERSION is BRANCH here for now |
103 | | - TASK_ARGS=("$VERSION") |
104 | | - ;; |
105 | | - *) |
106 | | - echo -e "\nUsage:\n\t $CMD is not supported right now\n" |
107 | | - exit 1 |
108 | | -esac |
109 | | - |
110 | | - |
111 | | -# ------------------------------------------------------- # |
112 | | -# Build Container |
113 | | -# ------------------------------------------------------- # |
114 | | - |
115 | | -echo -e "\033[34;1mINFO: building $product container\033[0m" |
116 | | - |
117 | | -#docker build --file .ci/DockerFile --tag ${product} \ |
118 | | -# --build-arg USER_ID="$(id -u)" \ |
119 | | -# --build-arg GROUP_ID="$(id -g)" . |
120 | | - |
121 | | - |
122 | | -# ------------------------------------------------------- # |
123 | | -# Run the Container |
124 | | -# ------------------------------------------------------- # |
125 | | - |
126 | | -echo -e "\033[34;1mINFO: running $product container\033[0m" |
127 | | - |
128 | | -#docker run \ |
129 | | -# --env "DOTNET_VERSION" \ |
130 | | -# --name test-runner \ |
131 | | -# --volume $REPO_BINDING \ |
132 | | -# --rm \ |
133 | | -# $product \ |
134 | | -# /bin/bash -c "./build.sh $TASK ${TASK_ARGS[*]} && chown -R $(id -u):$(id -g) ." |
135 | | - |
136 | | -# ------------------------------------------------------- # |
137 | | -# Post Command tasks & checks |
138 | | -# ------------------------------------------------------- # |
139 | | - |
140 | | -if [[ "$CMD" == "assemble" ]]; then |
141 | | - python $repo/utils/build-dists.py $VERSION |
142 | | - cp $repo/dist/* $repo/.ci/output |
143 | | - cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - |
144 | | - |
145 | | - if compgen -G ".ci/output/*" > /dev/null; then |
146 | | - echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" |
147 | | - exit 0 |
148 | | - else |
149 | | - echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m" |
150 | | - exit 1 |
151 | | - fi |
152 | | -fi |
153 | | - |
154 | | -if [[ "$CMD" == "bump" ]]; then |
155 | | - echo "TODO" |
156 | | -fi |
157 | | - |
158 | | -if [[ "$CMD" == "codegen" ]]; then |
159 | | - echo "TODO" |
160 | | -fi |
161 | | - |
162 | | -if [[ "$CMD" == "docsgen" ]]; then |
163 | | - echo "TODO" |
164 | | -fi |
165 | | - |
166 | | -if [[ "$CMD" == "examplesgen" ]]; then |
167 | | - echo "TODO" |
| 8 | +if [[ "$1" == "assemble" ]]; then |
| 9 | + mkdir -p $BASE_DIR/.ci/output |
| 10 | + docker build . --tag elastic/elasticsearch-py -f .ci/Dockerfile |
| 11 | + docker run --rm -v $BASE_DIR/.ci/output:/code/elasticsearch-py/dist \ |
| 12 | + elastic/elasticsearch-py \ |
| 13 | + python /code/elasticsearch-py/utils/build-dists.py $2 |
| 14 | + cd ./.ci/output && tar -czvf elasticsearch-py-$2.tar.gz * && cd - |
| 15 | + exit 0 |
168 | 16 | fi |
169 | 17 |
|
170 | 18 | echo "Must be called with '.ci/make.sh [command]" |
|
0 commit comments