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 0f4ca9b

Browse files
Merge pull request #1 from customink/UpdateImages
Latest Images; Single Version/Build Refs; Test System;
2 parents 14a5be6 + b56c398 commit 0f4ca9b

File tree

16 files changed

+122
-17
lines changed

16 files changed

+122
-17
lines changed

‎.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
on: [push]
3+
jobs:
4+
test:
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: Build
16+
run: |
17+
./bin/build
18+
- name: Test 2.5
19+
run: |
20+
./bin/test 2.5
21+
- name: Test 2.7
22+
run: |
23+
./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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
[![Test](https://github.com/customink/mysql2-lambda/actions/workflows/test.yml/badge.svg)](https://github.com/customink/mysql2-lambda/actions/workflows/test.yml)
3+
14
# Mysql2 Lambda Gem
25

36
<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 +17,7 @@ Part of a suite of open source projects from **[Lamby: Simple Rails & AWS Lambda
1417

1518
## Methodology
1619

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.
20+
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.
1821

1922
```shell
2023
$ ldd mysql2.so
@@ -41,7 +44,12 @@ Clone or fork this repository, make sure you have Docker installed, then run the
4144
./bin/build
4245
```
4346

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

4654
## License
4755

‎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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
sleep 10
13+
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 によって変換されたページ (->オリジナル) /