From b9f29134ee187f2a572f499f5a1b72fa1990331d Mon Sep 17 00:00:00 2001 From: sue445 Date: Thu, 16 Jan 2025 00:05:49 +0900 Subject: [PATCH 1/3] Add job for alpine --- .github/workflows/build.yml | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c48beb49..37b8245d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,6 +97,80 @@ jobs: webhook-url: ${{ secrets.SLACK_WEBHOOK }} matrix: ${{ toJson(matrix) }} + build-and-test-alpine: + name: "build-and-test-alpine (Go ${{ matrix.go }}, Ruby ${{ matrix.ruby }})" + + needs: + - generate-matrix + + runs-on: ubuntu-latest + + container: "ruby:${{ matrix.ruby }}-alpine" + + strategy: + fail-fast: false + + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - run: apk update + - run: apk add git alpine-sdk libffi-dev + + - name: bundle install + run: | + set -xe + bundle config --local path vendor/bundle/ + bundle install --jobs 4 + + - name: Cache vendor/bundle + uses: actions/cache@v4 + with: + path: vendor/bundle + key: v1-alpine-${{ matrix.ruby }}-${{ github.sha }} + restore-keys: | + v1-alpine-${{ matrix.ruby }}- + + - name: build and test (Go) + run: | + set -xe + bundle exec rake go:test + bundle exec rake go:testrace + + - name: build and test (Ruby) + run: bundle exec rake + working-directory: ${{ env.TEST_GEM_DIR }} + + # FIXME: workaround for gcov2lcov warning + - run: rm -rf vendor/ + + - name: Convert coverage to lcov + uses: jandelgado/gcov2lcov-action@v1 + with: + infile: coverage.out + outfile: coverage.lcov + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: coverage.lcov + continue-on-error: true # NOTE: secrets cannot be obtained with forked repository PR + + - name: Slack Notification (not success) + uses: act10ns/slack@v2 + if: "! success()" + continue-on-error: true + with: + status: ${{ job.status }} + webhook-url: ${{ secrets.SLACK_WEBHOOK }} + matrix: ${{ toJson(matrix) }} + go-lint: name: "go-lint (Ruby ${{ matrix.ruby }})" @@ -236,6 +310,7 @@ jobs: notify: needs: - build-and-test + - build-and-test-alpine - go-lint - ruby-lint - ruby-rbs From 846ecf455503ddf3032e53ba2714d444bea92b9b Mon Sep 17 00:00:00 2001 From: sue445 Date: Thu, 16 Jan 2025 23:52:19 +0900 Subject: [PATCH 2/3] Add alpine Dockerfile --- .dockerignore | 8 ++++++++ README.md | 13 +++++++++++++ _dockerfiles/alpine.dockerfile | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .dockerignore create mode 100644 _dockerfiles/alpine.dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f271ab7e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.bundle/ +.gem_rbs_collection/ +.git/ +.yardoc/ +doc/ +vendor/ +**/*.so +**/*.bundle diff --git a/README.md b/README.md index 8ff3eb8b..2842e408 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,19 @@ Run `bundle exec rake build_all`. See `bundle exec rake -T` for more tasks. +### Build in docker container +e.g. + +```bash +docker build --file=_dockerfiles/alpine.dockerfile -t go-gem-wrappper . +# or +docker build --file=_dockerfiles/alpine.dockerfile -t go-gem-wrappper --build-arg GO_VERSION=1.23 --build-arg RUBY_VERSION=3.4 . + +docker run --rm -it go-gem-wrappper sh +``` + +Run `bundle exec rake build_all` in container. + ### See `godoc` in local ```bash go install golang.org/x/tools/cmd/godoc@latest diff --git a/_dockerfiles/alpine.dockerfile b/_dockerfiles/alpine.dockerfile new file mode 100644 index 00000000..2ab12cf1 --- /dev/null +++ b/_dockerfiles/alpine.dockerfile @@ -0,0 +1,32 @@ +ARG GO_VERSION=1.23 +ARG RUBY_VERSION=3.4 +ARG ALPINE_VERSION=3.21 + +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golang + +FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION} + +RUN apk update && \ + apk add --no-cache git alpine-sdk libffi-dev \ + gdb strace binutils valgrind # for debug in container + +COPY --from=golang /usr/local/go /usr/local/go +COPY --from=golang /go /go + +ENV PATH=/go/bin:/usr/local/go/bin:$PATH \ + GOPATH=/go \ + GOLANGCI_LINT_VERSION=v1.60.3 + +RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLANGCI_LINT_VERSION} + +WORKDIR /app + +COPY Gemfile Gemfile.lock ./ +COPY _gem/go_gem.gemspec _gem/ +COPY _gem/lib/go_gem/version.rb _gem/lib/go_gem/ + +RUN bundle config --local path vendor/bundle/ && \ + bundle config --local deployment true && \ + bundle install --jobs 4 + +COPY . . From 48406bb1d2b95e31f4598cbcc2247d55cf516af7 Mon Sep 17 00:00:00 2001 From: sue445 Date: Fri, 24 Jan 2025 23:39:07 +0900 Subject: [PATCH 3/3] [WIP] Add debug flags example gem --- ruby/testdata/example/ext/example/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/testdata/example/ext/example/extconf.rb b/ruby/testdata/example/ext/example/extconf.rb index c1769e7e..2a025e52 100644 --- a/ruby/testdata/example/ext/example/extconf.rb +++ b/ruby/testdata/example/ext/example/extconf.rb @@ -12,5 +12,5 @@ append_cflags("-fvisibility=hidden") ############ Appended for go native extension -create_go_makefile("example/example") +create_go_makefile("example/example", go_build_args: "-gcflags='all=-N -l'") ############ Appended for go native extension