Skip to content

Commit

Permalink
Merge pull request flant#324 from flant/migrate_to_go_1_16
Browse files Browse the repository at this point in the history
Migrate to Go 1.16
  • Loading branch information
diafour authored Oct 13, 2021
2 parents 88907c0 + 3811f54 commit bfe409c
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 347 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ jobs:
build_linux_binary:
name: Build shell-operator binary
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Check out shell-operator code
uses: actions/[email protected]
Expand Down Expand Up @@ -74,15 +71,15 @@ jobs:
- name: Prepare environment
run: |
echo ::set-env name=CGO_ENABLED::1
echo "CGO_ENABLED=1" >> "${GITHUB_ENV}"
CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}
echo "CGO_CFLAGS=${CGO_CFLAGS}" >> "${GITHUB_ENV}"
CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}
echo "CGO_LDFLAGS=${CGO_LDFLAGS}" >> "${GITHUB_ENV}"
echo ::set-env name=GOOS::linux
echo "GOOS=linux" >> "${GITHUB_ENV}"
- name: Build binary
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/code-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
name: Go code style
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16

- uses: actions/[email protected]

Expand All @@ -25,10 +25,10 @@ jobs:
name: codespell
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16

- uses: actions/[email protected]
with:
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ jobs:
run_linter:
name: Run linter
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Check out shell-operator code
uses: actions/[email protected]
Expand Down Expand Up @@ -75,15 +72,15 @@ jobs:
- name: Prepare environment
run: |
echo ::set-env name=CGO_ENABLED::1
echo "CGO_ENABLED=1" >> "${GITHUB_ENV}"
CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}
echo "CGO_CFLAGS=${CGO_CFLAGS}" >> "${GITHUB_ENV}"
CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}
echo "CGO_LDFLAGS=${CGO_LDFLAGS}" >> "${GITHUB_ENV}"
echo ::set-env name=GOOS::linux
echo "GOOS=linux" >> "${GITHUB_ENV}"
- name: Run golangci-lint
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-dev-amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
name: context.payload.label.name,
});
} catch (e) {
console.log(`Error occured while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
console.log(`Error occurred while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
}
build_dev_image:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
name: context.payload.label.name,
});
} catch (e) {
console.log(`Error occured while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
console.log(`Error occurred while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
}
build_dev_image:
Expand Down
125 changes: 44 additions & 81 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ jobs:
name: context.payload.label.name,
});
} catch (e) {
console.log(`Error occured while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
console.log(`Error occurred while remove label. Possibly label is already removed. Ignore '${typeof e}' error.`);
}
build_and_run_unit_tests:
name: Build and unit tests
if: github.event_name == 'push' && github.event.ref != 'refs/heads/master'
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Check out shell-operator code
uses: actions/[email protected]
Expand Down Expand Up @@ -105,15 +102,15 @@ jobs:
- name: Prepare environment
run: |
echo ::set-env name=CGO_ENABLED::1
echo "CGO_ENABLED=1" >> "${GITHUB_ENV}"
CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}
echo "CGO_CFLAGS=${CGO_CFLAGS}" >> "${GITHUB_ENV}"
CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}
echo "CGO_LDFLAGS=${CGO_LDFLAGS}" >> "${GITHUB_ENV}"
echo ::set-env name=GOOS::linux
echo "GOOS=linux" >> "${GITHUB_ENV}"
- name: Run unit tests
run: |
Expand All @@ -125,14 +122,11 @@ jobs:
name: Download modules and build libjq
if: (github.event_name == 'push' && github.event.ref == 'refs/heads/master') || (github.event_name == 'pull_request' && github.event.label.id == 1838578615)
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Check out shell-operator code
uses: actions/[email protected]
Expand Down Expand Up @@ -203,17 +197,14 @@ jobs:
if: (github.event_name == 'push' && github.event.ref == 'refs/heads/master') || (github.event_name == 'pull_request' && github.event.label.id == 1838578615)
needs: prepare_build_dependencies
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Download go modules artifact
uses: actions/download-artifact@master
Expand All @@ -235,17 +226,17 @@ jobs:
run: |
export COVERAGE_DIR=$GITHUB_WORKSPACE/coverage_reports/unit_tests/${{ matrix.os }}
mkdir -p $COVERAGE_DIR
echo ::set-env name=COVERAGE_DIR::$COVERAGE_DIR
echo "COVERAGE_DIR=$COVERAGE_DIR" >> "${GITHUB_ENV}"
echo ::set-env name=CGO_ENABLED::1
echo "CGO_ENABLED=1" >> "${GITHUB_ENV}"
CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}
echo "CGO_CFLAGS=${CGO_CFLAGS}" >> "${GITHUB_ENV}"
CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}
echo "CGO_LDFLAGS=${CGO_LDFLAGS}" >> "${GITHUB_ENV}"
echo ::set-env name=GOOS::linux
echo "GOOS=linux" >> "${GITHUB_ENV}"
shell: bash

Expand All @@ -271,19 +262,25 @@ jobs:
strategy:
fail-fast: true
matrix:
k8s_version: ["1.16", "1.19", "1.20"]
include:
- k8s_version: "1.16"
kind_node_image: "kindest/node:v1.16.15"
cluster_name: "kube-1-16"
- k8s_version: "1.19"
kind_node_image: "kindest/node:v1.19.7"
cluster_name: "kube-1-19"
- k8s_version: "1.20"
kind_node_image: "kindest/node:v1.20.2"
cluster_name: "kube-1-20"
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
go-version: 1.16

- name: Download go modules artifact
uses: actions/download-artifact@master
Expand All @@ -301,71 +298,37 @@ jobs:
name: libjq
path: libjq

- name: Prepare environment
- name: Install ginkgo
run: |
# note that onsi/ginkgo is replaced by flant/ginkgo with fixes for combining coverage
go build github.com/onsi/ginkgo/ginkgo
./ginkgo version
echo ::set-env name=KIND_CLUSTER_VERSION::${{ matrix.k8s_version }}
export COVERAGE_DIR=$GITHUB_WORKSPACE/coverage_reports/integration_tests/${{ matrix.os }}-k8s-${{ matrix.k8s_version }}
mkdir -p $COVERAGE_DIR
echo ::set-env name=COVERAGE_DIR::$COVERAGE_DIR
echo ::set-env name=CGO_ENABLED::1
- name: Prepare environment
run: |
echo "CGO_ENABLED=1" >> "${GITHUB_ENV}"
CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}
echo "CGO_CFLAGS=${CGO_CFLAGS}" >> "${GITHUB_ENV}"
CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}
echo "CGO_LDFLAGS=${CGO_LDFLAGS}" >> "${GITHUB_ENV}"
echo "GOOS=linux" >> "${GITHUB_ENV}"
echo ::set-env name=GOOS::linux
- name: Start kind cluster
uses: engineerd/[email protected]
with:
version: "v0.11.1"
image: ${{ matrix.kind_node_image }}
name: ${{ matrix.cluster_name }}

- name: Run integration tests
env:
CLUSTER_NAME: ${{ matrix.cluster_name }}
run: |
./ginkgo \
--tags 'integration test' \
--vet off \
--race \
--cover \
--coverpkg=github.com/flant/shell-operator/pkg/...,github.com/flant/shell-operator/test/utils \
--coverprofile=coverage.out \
--outputdir=${COVERAGE_DIR} \
-p \
-r test/integration
- name: Upload coverage artifact
uses: actions/upload-artifact@v2
with:
name: coverage_reports
path: coverage_reports


upload_coverage:
name: Upload coverage
if: (github.event_name == 'push' && github.event.ref == 'refs/heads/master') || (github.event_name == 'pull_request' && github.event.label.id == 1838578615) # push master or ':robot: run e2e matrix' label
needs:
- unit_tests
- integration_tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Download coverage artifact
uses: actions/download-artifact@v2
with:
name: coverage_reports
path: coverage_reports

- name: Upload report to codeclimate.com
run: |
du -ah coverage_reports
export COVERAGE_DIR=coverage_reports
export GIT_BRANCH=${GITHUB_REF:11}
export GIT_COMMIT_SHA=$GITHUB_SHA
./scripts/ci/codeclimate_upload.sh
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq

# Go builder.
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.15-alpine3.12 AS builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.16-alpine3.14 AS builder

ARG appVersion=latest
RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev
Expand All @@ -24,12 +24,12 @@ RUN CGO_ENABLED=1 \
./cmd/shell-operator

# Final image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14
ARG TARGETPLATFORM
RUN apk --no-cache add ca-certificates bash sed tini && \
kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
echo "Download kubectl for ${kubectlArch}" && \
wget https://storage.googleapis.com/kubernetes-release/release/v1.19.4/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
wget https://storage.googleapis.com/kubernetes-release/release/v1.19.11/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl && \
mkdir /hooks
ADD frameworks/shell /frameworks/shell
Expand Down
Loading

0 comments on commit bfe409c

Please sign in to comment.