diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml new file mode 100644 index 0000000..fcc0d2a --- /dev/null +++ b/.github/workflows/build-and-push-image.yml @@ -0,0 +1,59 @@ +# see: +# - https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages +# - https://github.com/docker/build-push-action/tree/v5.0.0 + +name: Create and publish a Docker image + +on: workflow_dispatch + +env: + REGISTRY: ghcr.io + REPOSITORY_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: self-hosted + timeout-minutes: 720 + permissions: + contents: read + packages: write + strategy: + matrix: + mysql_version: + - 8.0.28 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set image name + run: | + echo "IMAGE_NAME=`echo ${REPOSITORY_NAME} | tr '[A-Z]' '[a-z]'`" >>${GITHUB_ENV} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + build-args: MYSQL_VERSION=${{ matrix.mysql_version }} + platforms: linux/amd64,linux/arm64 + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.mysql_version }}-${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5bae2de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +FROM ubuntu:jammy + +ENV PATH /usr/local/mysql/bin:$PATH + +# install required packages +# https://github.com/openssl/openssl#build-and-install +# https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html +RUN apt-get update \ + && apt-get install -y perl \ + && apt-get install -y wget cmake gcc g++ libncurses-dev libudev-dev dpkg-dev pkg-config bison \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# install libssl 1.1 +# MySQLが3系に対応しておらず、jammyではlibssl-devは3系のみなので、ソースからインストールする +# 以下のリンク先にあるバグチケットが解消されれば、libssl-devをインストールすることで解決可能 +# https://bugs.mysql.com/bug.php?id=102405 +# https://packages.ubuntu.com/jammy/libssl-dev +ENV OPENSSL_VERSION 1.1.1o +RUN cd /tmp \ + && wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \ + && tar xvzf openssl-${OPENSSL_VERSION}.tar.gz \ + && cd openssl-${OPENSSL_VERSION} \ + && ./config \ + && make \ + && make install \ + && ldconfig + +ENV Q4M_PLUGIN q4m +ARG MYSQL_VERSION + +# install mysql-build + q4m plugin installer, build mysql + q4m, remove workdir +RUN cd /tmp \ + && wget -O q4m-master.tar.gz https://github.com/DeNA/q4m/archive/master.tar.gz \ + && tar xvzf q4m-master.tar.gz \ + && mv q4m-master /tmp/q4m \ + && wget -O mysql-build-master.tar.gz https://github.com/kamipo/mysql-build/archive/master.tar.gz \ + && tar xvzf mysql-build-master.tar.gz \ + && mv mysql-build-master /usr/local/mysql-build \ + && mv /tmp/q4m/docker/${Q4M_PLUGIN} /usr/local/mysql-build/share/mysql-build/plugins/${Q4M_PLUGIN} \ + && cd ~/ \ + && /usr/local/mysql-build/bin/mysql-build -v ${MYSQL_VERSION} /usr/local/mysql ${Q4M_PLUGIN} \ + && rm -rf /usr/local/mysql-build \ + && rm /tmp/*master.tar.gz + +# user, group +RUN mkdir /var/lib/mysql \ + && groupadd mysql \ + && useradd -r -g mysql -s /bin/false mysql \ + && chown -R mysql:mysql /var/lib/mysql + +# setup mysql +# COPY my.cnf /etc/mysql/my.cnf +RUN mysqld --initialize-insecure --user=mysql \ + && mysql_ssl_rsa_setup \ + && mysqld --daemonize --skip-networking --user mysql --socket /tmp/mysql.sock \ + && echo "CREATE USER 'root'@'%'; GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; " | mysql -uroot -hlocalhost --socket /tmp/mysql.sock \ + && cat /usr/local/mysql/support-files/install-q4m.sql | mysql -uroot -hlocalhost --socket /tmp/mysql.sock \ + && mysqladmin shutdown -uroot --socket /tmp/mysql.sock + +EXPOSE 3306 +ENTRYPOINT [ "mysqld", "--user=mysql" ] \ No newline at end of file diff --git a/my.cnf b/my.cnf new file mode 100644 index 0000000..c8a24af --- /dev/null +++ b/my.cnf @@ -0,0 +1,4 @@ +[mysqld] +basedir = /usr/local/mysql +datadir = /var/lib/mysql +socket = /var/lib/mysql/mysql.sock \ No newline at end of file