From 70e5bc8bdd99887a63806800972b70df4c1c2333 Mon Sep 17 00:00:00 2001 From: Marko Sabec Date: Sun, 27 Jun 2021 17:14:27 +0200 Subject: [PATCH 1/2] Add checks, snapshot and release workflows --- .drone.yml | 69 ----------------------- .github/workflows/checks.yml | 28 +++++++++ .github/workflows/release.yml | 100 +++++++++++++++++++++++++++++++++ .github/workflows/snapshot.yml | 56 ++++++++++++++++++ .gitignore | 2 + Dockerfile | 40 +++++++++++++ Makefile | 2 +- 7 files changed, 227 insertions(+), 70 deletions(-) delete mode 100644 .drone.yml create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/snapshot.yml create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 7619331a5..000000000 --- a/.drone.yml +++ /dev/null @@ -1,69 +0,0 @@ -kind: pipeline -name: Build -type: docker - -steps: - - name: "Quality Control" - image: cortezaproject/corteza-server-builder:1.16 - pull: always - commands: - - make test.unit - - - name: "Build release (tag)" - image: cortezaproject/corteza-server-builder:1.16 - environment: - RELEASE_SFTP_KEY: { from_secret: RELEASE_SFTP_KEY } - RELEASE_SFTP_URI: { from_secret: RELEASE_SFTP_URI } - commands: - - make release-clean release BUILD_OS=linux BUILD_ARCH=amd64 BUILD_VERSION=${DRONE_TAG} -# - make release-clean release BUILD_OS=darwin BUILD_ARCH=amd64 BUILD_VERSION=${DRONE_TAG} -# - make release-clean release BUILD_OS=windows BUILD_ARCH=amd64 BUILD_VERSION=${DRONE_TAG} - - make upload - when: - event: [ tag ] - ref: - - refs/tags/20??.3.* - - refs/tags/20??.6.* - - refs/tags/20??.9.* - - refs/tags/20??.12.* - ---- - -kind: pipeline -name: Integration -type: docker - -steps: - - name: test - image: cortezaproject/corteza-server-builder:1.16 - pull: always - environment: - GOFLAGS: -mod=vendor - CGO_ENABLED: "1" - GOOS: linux - GOARCH: amd64 - CI: circleci - - # Corteza basics - AUTH_OIDC_ENABLED: "0" - AUTH_JWT_SECRET: FBjddkvwQib0d4usifnEGVr1bncuVeD7 - CORREDOR_CLIENT_CERTIFICATES_ENABLED: "false" - CORREDOR_ENABLED: "false" - - # Storage backends - DB_DSN: sqlite3://file::memory:?cache=shared&mode=memory - # for now, we only run Store tests with SQLite - RDBMS_SQLITE_DSN: sqlite3://file::memory:?cache=shared&mode=memory - commands: - - make test.coverprofile.all - - - name: coverage - image: plugins/codecov - settings: - token: 628a7104-4ec8-46ef-a3a8-50b0c2507082 - files: - - .cover.out - -trigger: - event: - exclude: [ pull_request ] diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 000000000..1be80933c --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,28 @@ +name: checks + +on: [pull_request] + + +jobs: + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.16 + - uses: actions/cache@v2 + if: ${{ !env.ACT }} + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - run: make test.coverprofile.all + env: + GOFLAGS: -mod=readonly + - uses: codecov/codecov-action@v1 + with: + token: 628a7104-4ec8-46ef-a3a8-50b0c2507082 + files: .cover.out + fail_ci_if_error: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..ebfc551fe --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,100 @@ +name: release + +on: + push: + tags: + - '**' + + +jobs: + + test: + runs-on: ubuntu-latest + env: + GOFLAGS: -mod=readonly + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.16 + - uses: actions/cache@v2 + if: ${{ !env.ACT }} + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - run: make test.all + + release-linux: + runs-on: ubuntu-latest + needs: + - test + env: + GOFLAGS: -mod=readonly + BUILD_OS: linux + BUILD_ARCH: amd64 + RELEASE_SFTP_KEY: ${{ secrets.RELEASE_SFTP_KEY }} + RELEASE_SFTP_URI: ${{ secrets.RELEASE_SFTP_URI }} + steps: + - run: echo "BUILD_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.16 + - uses: actions/cache@v2 + if: ${{ !env.ACT }} + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - run: make release-clean release + - run: make upload + if: ${{ !env.ACT }} + + release-darwin: + runs-on: macos-latest + needs: + - test + env: + GOFLAGS: -mod=readonly + BUILD_OS: darwin + BUILD_ARCH: amd64 + BUILD_VERSION: ${{ format(github.ref, 'refs/tags/', '') }} + RELEASE_SFTP_KEY: ${{ secrets.RELEASE_SFTP_KEY }} + RELEASE_SFTP_URI: ${{ secrets.RELEASE_SFTP_URI }} + steps: + - run: echo "BUILD_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.16 + - uses: actions/cache@v2 + if: ${{ !env.ACT }} + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - run: make release-clean release + - run: make upload + if: ${{ !env.ACT }} + + release-docker: + runs-on: ubuntu-latest + needs: + - test + env: + GOFLAGS: -mod=readonly + BUILD_OS: linux + BUILD_ARCH: amd64 + steps: + - run: echo "BUILD_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - uses: actions/checkout@v2 + - uses: docker/login-action@v1 + if: ${{ !env.ACT }} + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - run: docker build -t cortezaproject/corteza-server:${{ env.BUILD_VERSION }} . + if: ${{ !env.ACT }} + - run: docker push cortezaproject/corteza-server:${{ env.BUILD_VERSION }} + if: ${{ !env.ACT }} diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 000000000..46c1f50ef --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,56 @@ +name: snapshot + +on: + push: + branches: + - 2021.3.x* + - 2021.6.x* + - 2021.9.x* + - 2021.12.x* + + +jobs: + + test: + runs-on: ubuntu-latest + env: + GOFLAGS: -mod=readonly + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.16 + - uses: actions/cache@v2 + if: ${{ !env.ACT }} + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - run: make test.all + + snapshot-docker: + runs-on: ubuntu-latest + needs: + - test + env: + GOFLAGS: -mod=readonly + BUILD_OS: linux + BUILD_ARCH: amd64 + BUILD_VERSION: ${GITHUB_SHA} + steps: + - uses: actions/checkout@v2 + - uses: docker/login-action@v1 + if: ${{ !env.ACT }} + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - uses: docker/login-action@v1 + if: ${{ !env.ACT }} + with: + registry: ghcr.io + username: ${{ secrets.GH_USERNAME }} + password: ${{ secrets.GH_TOKEN }} + - run: docker build -t ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION }} . + if: ${{ !env.ACT }} + - run: docker push ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION }} + if: ${{ !env.ACT }} diff --git a/.gitignore b/.gitignore index d7a4eefa5..537122a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ profile.coverprofile /gin-bin /.vscode /federation/etc/.env* +/.act* +/workflow diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..661a42c11 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# build stage +FROM golang:1.16-alpine as build-stage + +ENV GOFLAGS='-mod=readonly' +ENV BUILD_OS=linux +ENV BUILD_ARCH=amd64 +ENV BUILD_VERSION=latest + +RUN apk add build-base --no-cache + +WORKDIR /corteza + +COPY . ./ + +RUN make release-clean release + + +# deploy stage +FROM alpine:3 + +ENV STORAGE_PATH "/data" +ENV CORREDOR_ADDR "corredor:80" +ENV HTTP_ADDR "0.0.0.0:80" +ENV HTTP_WEBAPP_ENABLED "false" +ENV PATH "/corteza/bin:${PATH}" + +WORKDIR /corteza + +VOLUME /data + +COPY --from=build-stage /corteza/build/pkg/corteza-server ./ + +HEALTHCHECK --interval=30s --start-period=1m --timeout=30s --retries=3 \ + CMD curl --silent --fail --fail-early http://127.0.0.1:80/healthcheck || exit 1 + +EXPOSE 80 + +ENTRYPOINT ["./bin/corteza-server"] + +CMD ["serve-api"] diff --git a/Makefile b/Makefile index 434565a67..c6922189c 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ release-clean: rm -rf $(BUILD_DEST_DIR)/$(RELEASE_NAME) upload: $(RELEASE_PKEY) - @ echo "put $(BUILD_DEST_DIR)/*.tar.gz" | sftp -q -i $(RELEASE_PKEY) $(RELEASE_SFTP_URI) + @ echo "put $(BUILD_DEST_DIR)/*.tar.gz" | sftp -q -o "StrictHostKeyChecking no" -i $(RELEASE_PKEY) $(RELEASE_SFTP_URI) @ rm -f $(RELEASE_PKEY) $(RELEASE_PKEY): From cdd1aa452637f2170091f60c6fdb0cf3a6fdf9eb Mon Sep 17 00:00:00 2001 From: Marko Sabec Date: Thu, 8 Jul 2021 08:50:30 +0200 Subject: [PATCH 2/2] Add branch snapshots --- .github/workflows/snapshot.yml | 14 ++++++++++---- .gitignore | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 46c1f50ef..7c08926f7 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -7,7 +7,8 @@ on: - 2021.6.x* - 2021.9.x* - 2021.12.x* - + - 2022.3.x* + - 2022.9.x* jobs: @@ -36,8 +37,9 @@ jobs: GOFLAGS: -mod=readonly BUILD_OS: linux BUILD_ARCH: amd64 - BUILD_VERSION: ${GITHUB_SHA} + BUILD_VERSION_SHA: ${GITHUB_SHA} steps: + - run: echo "BUILD_VERSION_REF=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - uses: actions/checkout@v2 - uses: docker/login-action@v1 if: ${{ !env.ACT }} @@ -50,7 +52,11 @@ jobs: registry: ghcr.io username: ${{ secrets.GH_USERNAME }} password: ${{ secrets.GH_TOKEN }} - - run: docker build -t ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION }} . + - run: | + docker build -t ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION_SHA }} \ + -t ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION_REF }} . if: ${{ !env.ACT }} - - run: docker push ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION }} + - run: docker push ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION_SHA }} + if: ${{ !env.ACT }} + - run: docker push ghcr.io/cortezaproject/corteza-server:${{ env.BUILD_VERSION_REF }} if: ${{ !env.ACT }} diff --git a/.gitignore b/.gitignore index 537122a0d..18c86c909 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,7 @@ profile.coverprofile /gin-bin /.vscode /federation/etc/.env* + +# https://github.com/nektos/act /.act* /workflow