Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit a06fd28

Browse files
Latest Images; Single Version/Build Refs; Test System;
1 parent 14a5be6 commit a06fd28

File tree

16 files changed

+114
-17
lines changed

16 files changed

+114
-17
lines changed

‎.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI/CD
2+
on: [push]
3+
jobs:
4+
cicd:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v1
9+
- name: Bootstrap
10+
run: |
11+
./bin/bootstrap
12+
- name: Setup
13+
run: |
14+
./bin/setup
15+
- name: Test
16+
run: |
17+
./bin/test 2.5
18+
./bin/test 2.7

‎BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

‎Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM lambci/lambda:build-ruby2.5
1+
FROM amazon/aws-sam-cli-build-image-ruby2.5
22

33
WORKDIR /build
44

@@ -18,6 +18,7 @@ RUN git clone https://github.com/NixOS/patchelf.git && \
1818
make install
1919

2020
RUN echo '== MySQL Connector =='
21+
RUN yum install -y cmake
2122
RUN curl -L https://downloads.mysql.com/archives/get/p/19/file/mysql-connector-c-6.1.11-src.tar.gz > mysql-connector-c-6.1.11-src.tar.gz && \
2223
tar -xf mysql-connector-c-6.1.11-src.tar.gz && \
2324
cd mysql-connector-c-6.1.11-src && \
@@ -33,13 +34,13 @@ RUN rm -rf /usr/local/mysql/lib/libmysqlclient.so* && \
3334

3435
RUN echo '== Patch MySQL2 Gem =='
3536
RUN patchelf --add-needed librt.so.1 \
36-
/var/runtime/gems/mysql2-0.5.3/lib/mysql2/mysql2.so && \
37+
"/var/lang/lib/ruby/gems/2.5.0/gems/mysql2-${MYSQL_VERSION}/lib/mysql2/mysql2.so" && \
3738
patchelf --add-needed libstdc++.so.6 \
38-
/var/runtime/gems/mysql2-0.5.3/lib/mysql2/mysql2.so
39+
"/var/lang/lib/ruby/gems/2.5.0/gems/mysql2-${MYSQL_VERSION}/lib/mysql2/mysql2.so"
3940

4041
RUN echo '== Share Files =='
4142
RUN mkdir -p /build/share && \
42-
cp -r /var/runtime/gems/mysql2-$MYSQL_VERSION/* /build/share && \
43+
cp -r "/var/lang/lib/ruby/gems/2.5.0/gems/mysql2-${MYSQL_VERSION}"/* /build/share && \
4344
rm -rf /build/share/ext \
4445
/build/share/README.md \
4546
/build/share/support

‎README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Mysql2 Lambda Gem
23

34
<a href="https://github.com/customink/lamby"><img src="https://user-images.githubusercontent.com/2381/59363668-89edeb80-8d03-11e9-9985-2ce14361b7e3.png" alt="Lamby: Simple Rails & AWS Lambda Integration using Rack." align="right" width="300" /></a>Very simple [Mysql2](https://github.com/brianmario/mysql2) gem precompiled for Amazon Linux 1 & 2 (Ruby 2.5 & 2.7) with statically linked `libmysqlclient` ready for any AWS Lambda usage, including Rails.
@@ -14,7 +15,7 @@ Part of a suite of open source projects from **[Lamby: Simple Rails & AWS Lambda
1415

1516
## Methodology
1617

17-
We used the `lambci/lambda:build-ruby2.5` Docker image from the [docker-lambda](https://github.com/lambci/docker-lambda) project to build the MySQL Connector/C's `libmysqlclient`. From there we ensure the Mysql2 gem statically includes that library. The resulting packaged gem and `mysql2.so` file looks something like this.
18+
We used the `amazon/aws-sam-cli-build-image-ruby2.5` Docker image from the [SAM CLI](https://github.com/aws/aws-sam-cli) project to build the MySQL Connector/C's `libmysqlclient`. From there we ensure the Mysql2 gem statically includes that library. The resulting packaged gem and `mysql2.so` file looks something like this.
1819

1920
```shell
2021
$ ldd mysql2.so
@@ -41,7 +42,12 @@ Clone or fork this repository, make sure you have Docker installed, then run the
4142
./bin/build
4243
```
4344

44-
You will now have a packaged gem in the root of your project.
45+
You will now have a packaged gem in the root of your project. Simple tests to make sure it works.
46+
47+
```shell
48+
./bin/test 2.5
49+
./bin/test 2.7
50+
```
4551

4652
## License
4753

‎VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.3

‎bin/_test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
MYSQL_VERSION=$(cat VERSION)
5+
MYSQL_BUILD_VERSION=$(cat BUILD)
6+
MYSQL_GEM_VERSION="${MYSQL_VERSION}.${MYSQL_BUILD_VERSION}"
7+
MYSQL_GEM_FILE="mysql2-lambda-${MYSQL_GEM_VERSION}.gem"
8+
9+
echo "Installing ${MYSQL_GEM_FILE} file..."
10+
gem install --local "$MYSQL_GEM_FILE"
11+
12+
ruby ./bin/_test-mysql2.rb

‎bin/_test-mysql2.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'mysql2'
2+
3+
EXPECTED = [{"one"=>1}]
4+
5+
client = Mysql2::Client.new host: "mysql", username: "root", password: "root"
6+
result = client.query("SELECT 1 AS one").each
7+
8+
if result == EXPECTED
9+
puts "PASSED! 🎉"
10+
else
11+
abort "Result #{result.inspect} failed to be expected #{EXPECTED.inspect}"
12+
end

‎bin/bootstrap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
set -e
43

54
docker -v 1ドル &> /dev/null

‎bin/build

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/bin/bash
2-
32
set -e
43

5-
export IMAGE_NAME=mysql2-lambda
6-
export MYSQL_VERSION=${MYSQL_VERSION:=0.5.3}
4+
IMAGE_NAME=mysql2-lambda
75

86
rm -rf ./share
97
mkdir ./share
@@ -15,9 +13,12 @@ docker run \
1513
sh -c "cp -r /build/share/* /share"
1614

1715
rm -rf ./gem && mkdir ./gem
16+
rm -rf */.gem
1817
cp -r ./share/* ./gem
1918
cp ./README.md ./gem
2019
cp ./CHANGELOG.md ./gem
20+
cp ./VERSION ./gem
21+
cp ./BUILD ./gem
2122
cp ./mysql2-lambda.gemspec ./gem
2223
cp ./lib/mysql2-lambda.rb ./gem/lib
2324

‎bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
IMAGE_NAME=mysql2-lambda
5+
6+
docker run \
7+
--interactive \
8+
--tty \
9+
--rm \
10+
--entrypoint "/bin/bash" \
11+
$IMAGE_NAME

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /