From 67628bbb2f1b0ebedacfbcc99c0532af70d7ca31 Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Tue, 5 Apr 2022 18:27:46 -0700 Subject: [PATCH 1/4] Improve the swagger gen scripts --- scripts/cosmos-swagger-gen.sh | 37 ++++++++++++++++++++++++----------- scripts/dcl-swagger-gen.sh | 15 +++++++++++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/scripts/cosmos-swagger-gen.sh b/scripts/cosmos-swagger-gen.sh index e801c90a8..730c1bded 100755 --- a/scripts/cosmos-swagger-gen.sh +++ b/scripts/cosmos-swagger-gen.sh @@ -1,22 +1,37 @@ #!/usr/bin/env bash -# possible values: "base" or "tx" +# Copyright 2022 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + TYPE=${1:-tx} +valid_values=(base tx) +if ! printf '%s\0' "${valid_values[@]}" | grep -qxFe "$TYPE"; then + printf '%s\n' "$TYPE is an invalid value" + exit 1 +fi echo "Generating Cosmos openapi for '$TYPE'" CONFIG_FILE="$PWD/scripts/swagger/config/cosmos-$TYPE-config.json" OUTPUT_FILE="$PWD/docs/static/cosmos-$TYPE-openapi.json" - COSMOS_SDK_VERSION="v0.44.4" -rm -rf ./tmp-swagger-gen mkdir -p ./tmp-swagger-gen - -# clone cosmos-sdk repo -git clone -b $COSMOS_SDK_VERSION --depth 1 https://github.com/cosmos/cosmos-sdk.git ./tmp-swagger-gen/cosmos-sdk +if [ ! -d ./tmp-swagger-gen/cosmos-sdk ]; then + git clone -b $COSMOS_SDK_VERSION --depth 1 https://github.com/cosmos/cosmos-sdk.git ./tmp-swagger-gen/cosmos-sdk +fi +trap "rm -rf ./tmp-swagger-gen" EXIT # generate openapi -pushd ./tmp-swagger-gen/cosmos-sdk -../../scripts/swagger/protoc-swagger-gen.sh $CONFIG_FILE $OUTPUT_FILE -popd - -rm -rf ./tmp-swagger-gen \ No newline at end of file +pushd ./tmp-swagger-gen/cosmos-sdk || exit +../../scripts/swagger/protoc-swagger-gen.sh "$CONFIG_FILE" "$OUTPUT_FILE" +popd || exit diff --git a/scripts/dcl-swagger-gen.sh b/scripts/dcl-swagger-gen.sh index 8f7ab2e26..ed9297c3c 100755 --- a/scripts/dcl-swagger-gen.sh +++ b/scripts/dcl-swagger-gen.sh @@ -1,7 +1,20 @@ #!/usr/bin/env bash +# Copyright 2022 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. echo "Generating DCL openapi ..." CONFIG_FILE="$PWD/scripts/swagger/config/dcl-config.json" OUTPUT_FILE="$PWD/docs/static/openapi.yml" -./scripts/swagger/protoc-swagger-gen.sh $CONFIG_FILE $OUTPUT_FILE \ No newline at end of file +./scripts/swagger/protoc-swagger-gen.sh "$CONFIG_FILE" "$OUTPUT_FILE" From d32df7b74ef7e22555ba3976d485508c954dbc9f Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Tue, 5 Apr 2022 18:28:09 -0700 Subject: [PATCH 2/4] Reduce the Docker scripts size --- scripts/Dockerfile | 103 +++++++++++++++++----------------- scripts/README.md | 2 +- scripts/cosmos-swagger-gen.sh | 7 +++ 3 files changed, 61 insertions(+), 51 deletions(-) diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 067406055..aa6721812 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,63 +1,66 @@ +# Copyright 2022 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + ################################################################################ # Image of a machine with installed swagger-combine and starport. ################################################################################ -FROM node - -# Install golang -ARG GO_VERSION -ENV GO_VERSION=${GO_VERSION:-1.17.2} -ENV BASH_ENV=/etc/bashrc -ENV PATH="${PATH}:/usr/local/go/bin" -RUN curl -L https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz -o /tmp/go.tar.gz \ - && rm -rf /usr/local/go \ - && tar -C /usr/local -xzf /tmp/go.tar.gz \ - && go version \ - && rm -f /tmp/go.tar.gz - -# Install protoc -ARG PROTOC_VERSION -ENV PROTOC_VERSION=${PROTOC_VERSION:-3.19.4} -RUN PROTOC_ZIP=protoc-${PROTOC_VERSION}-linux-x86_64.zip \ - && curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP} \ - && unzip -o $PROTOC_ZIP -d /usr/local bin/protoc \ - && unzip -o $PROTOC_ZIP -d /usr/local 'include/*' \ - && rm -f $PROTOC_ZIP - -# Install grpc-gateway tools -ENV PROTOC_GEN_GRPC_GATEWAY_VERSION=v2.8.0 -ENV PROTOC_GEN_OPENAPIV2_VERSION=v2.8.0 -ENV PROTOC_GEN_SWAGGER_VERSION=v1.16.0 +FROM alpine:3.15 as builder -RUN go install \ - github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@${PROTOC_GEN_GRPC_GATEWAY_VERSION} \ - github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@${PROTOC_GEN_OPENAPIV2_VERSION} - -RUN go install \ - github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@${PROTOC_GEN_SWAGGER_VERSION} +ARG STARPORT_VERSION -RUN npm install -g swagger-combine +ENV STARPORT_VERSION=${STARPORT_VERSION:-v0.19.3} +#ENV STARPORT_VERSION=${STARPORT_VERSION:-dev} +RUN apk --no-cache add \ + make=4.3-r0 \ + go=1.17.9-r0 \ + git=2.34.2-r0 \ + bash=5.1.16-r0 # Install starport -ARG STARPORT_VERSION -ENV STARPORT_VERSION=${STARPORT_VERSION:-0.19.3} -#ENV STARPORT_VERSION=${STARPORT_VERSION:-dev} +WORKDIR /tmp +RUN git clone https://github.com/tendermint/starport.git \ + && if [ "$STARPORT_VERSION" != "dev" ]; then \ + git -C /tmp/starport checkout -b ${STARPORT_VERSION:-v0.19.3} tags/${STARPORT_VERSION:-v0.19.3}; \ + fi \ + && make -C /tmp/starport build -RUN if [ "$STARPORT_VERSION" = "dev" ]; then \ - curl -L https://github.com/tendermint/starport/archive/refs/heads/develop.zip -o /tmp/starport.zip && \ - cd /tmp \ - && unzip starport.zip \ - && cd starport-develop \ - && make build \ - && cp ./dist/starport /usr/local/bin; \ - else \ - curl https://get.starport.network/starport@v${STARPORT_VERSION}! -o /tmp/startport \ - && bash /tmp/startport \ - && rm /tmp/startport; \ - fi +FROM alpine:3.15 +ENV PROTOC_GEN_GRPC_GATEWAY_VERSION=v2.8.0 +ENV PROTOC_GEN_OPENAPIV2_VERSION=v2.8.0 +ENV PROTOC_GEN_SWAGGER_VERSION=v1.16.0 ENV PATH="/root/go/bin:${PATH}" -ENV PATH="${PATH}:/usr/local/bin" -WORKDIR /dcl \ No newline at end of file +COPY --from=builder /tmp/starport/dist/starport /usr/local/bin/starport + +RUN apk --no-cache add \ + bash=5.1.16-r0 \ + git=2.34.2-r0 \ + go=1.17.9-r0 \ + protobuf=3.18.1-r1 \ + protobuf-dev=3.18.1-r1 \ + npm=8.1.3-r0 \ + && npm install -g swagger-combine@1.4.0 + +# Install grpc-gateway tools + +RUN go install \ + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@${PROTOC_GEN_GRPC_GATEWAY_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@${PROTOC_GEN_OPENAPIV2_VERSION} \ + && go install \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@${PROTOC_GEN_SWAGGER_VERSION} + +WORKDIR /dcl diff --git a/scripts/README.md b/scripts/README.md index 4e7423ec9..e27a50dbb 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -20,7 +20,7 @@ docker build -t ./scripts Run docker container (from the root of the project) in an interactive mode: ```bash -docker run -it -v "$PWD":/dcl /bin/bash +docker run -it --rm -v "$PWD":/dcl /bin/bash ``` ## Scripts diff --git a/scripts/cosmos-swagger-gen.sh b/scripts/cosmos-swagger-gen.sh index 730c1bded..41942bcc2 100755 --- a/scripts/cosmos-swagger-gen.sh +++ b/scripts/cosmos-swagger-gen.sh @@ -13,6 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o pipefail +set -o errexit +set -o nounset +if [[ "${DEBUG:-false}" == "true" ]]; then + set -o xtrace +fi + TYPE=${1:-tx} valid_values=(base tx) if ! printf '%s\0' "${valid_values[@]}" | grep -qxFe "$TYPE"; then From 33fec9d53b81c2f32d0b40a2d8578973a3bc12e8 Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Thu, 28 Apr 2022 13:42:25 -0700 Subject: [PATCH 3/4] Fix hadolint issues --- Dockerfile | 10 +++++----- integration_tests/deploy/Dockerfile | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4480fbaf7..836e3efd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,17 +19,17 @@ ############################ # STEP 1 build cosmovisor ############################ -FROM golang:alpine AS builder +FROM golang:alpine3.15 AS builder # git is required for fetching the dependencies. -RUN apk update && apk add --no-cache git - -RUN go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0 +RUN apk --no-cache add \ + git=2.34.2-r0 && \ + go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0 ############################ # STEP 2 build node image ############################ -FROM alpine:latest +FROM alpine:3.15 COPY --from=builder /go/bin/cosmovisor /usr/bin/ diff --git a/integration_tests/deploy/Dockerfile b/integration_tests/deploy/Dockerfile index fae70aa2c..64e8121aa 100644 --- a/integration_tests/deploy/Dockerfile +++ b/integration_tests/deploy/Dockerfile @@ -17,11 +17,11 @@ ################################################################################ FROM jrei/systemd-ubuntu:20.04 -RUN apt-get update && apt-get install -y \ - sudo \ - curl \ - netcat \ - iproute2 \ +RUN apt-get update && apt-get install -y --no-install-recommends \ + sudo=1.8.31-1ubuntu1.2 \ + curl=7.68.0-1ubuntu2.10 \ + netcat=1.206-1ubuntu1 \ + iproute2=5.5.0-1ubuntu1 \ && rm -rf /var/lib/apt/lists/* # test user From c5ed985154ef8fd1875e1ea8abd64cab2802d4bf Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Thu, 28 Apr 2022 13:43:02 -0700 Subject: [PATCH 4/4] Create GitHub workflow for validating Dockerfiles --- .github/workflows/on-demand_docker.yml | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/on-demand_docker.yml diff --git a/.github/workflows/on-demand_docker.yml b/.github/workflows/on-demand_docker.yml new file mode 100644 index 000000000..6ab840c2e --- /dev/null +++ b/.github/workflows/on-demand_docker.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2022 Samsung Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Check Docker files +# yamllint disable-line rule:truthy +on: + push: + branches: + - master + paths: + - '**/Dockerfile' + pull_request: + branches: + - master + paths: + - '**/Dockerfile' + +jobs: + check-dockerfile-lint: + name: Check Dockerfile lint issues (hadolint) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: hadolint/hadolint-action@v2.1.0 + with: + recursive: true