Skip to content

Commit 2c87602

Browse files
Merge pull request #233 from Sebastian-Webster/add-support-for-alpine-linux
Add support for Alpine Linux
2 parents 70bc8d5 + 5ebeab9 commit 2c87602

File tree

14 files changed

+217
-92
lines changed

14 files changed

+217
-92
lines changed

.github/workflows/os-compatibility.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,42 @@ jobs:
9292
if: ${{ failure() }}
9393
uses: actions/[email protected]
9494
with:
95-
name: docker-fedora-${{ matrix.version }}-${{ matrix.version-requirement }}
95+
name: docker-fedora-${{ matrix.version }}-${{ matrix.version-requirement }}-${{ matrix.ubuntu-version}}
9696
path: /tmp/mysqlmsn
97-
compression-level: 0
97+
compression-level: 0
98+
99+
alpine-docker:
100+
runs-on: ubuntu-${{ matrix.ubuntu-version}}
101+
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
#There is no 10.0.0 at the time of writing, but since greater than characters are not allowed in GitHub Actions artifacts names, 9.0.1 - 10.0.0 will be used instead of >9.0.0
106+
version-requirement: [ '8.4.0 - 9.0.0', '9.0.1 - 10.0.0']
107+
ubuntu-version: [24.04, 24.04-arm]
108+
109+
container: alpine:3.22
110+
111+
steps:
112+
- name: Install required libraries for test setup
113+
run: apk add git nodejs npm
114+
115+
- name: Install required libraries for MySQL on alpine
116+
run: apk add libaio libstdc++
117+
118+
- name: Checkout
119+
run: git clone https://github.com/${{ github.repository }} --branch ${{ github.head_ref || github.ref_name }} --single-branch --depth 1 mysqlmsn
120+
121+
- name: Install packages
122+
working-directory: mysqlmsn
123+
run: npm ci
124+
125+
- name: Print available storage space
126+
run: df -h
127+
128+
- name: Run tests
129+
working-directory: mysqlmsn
130+
env:
131+
VERSION_REQUIREMENT: ${{ matrix.version-requirement }}
132+
X_OFF: true
133+
run: npm run os-compat:ci

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ The name of the user to use to login to the database
8787
If on Windows, this is the name of the named pipe that MySQL is listening on. If not on Windows, this is the path to the socket that MySQL is listening on.
8888
- `xSocket: string`
8989
If on Windows, this is the name of the named pipe that the MySQL X Plugin is listening on. If not on Windows, this is the path that the MySQL X Plugin is listening on. If ```options.xEnabled``` is set to "OFF", this value will be an empty string.
90-
- `mysql: {version: string, versionIsInstalledOnSystem: boolean, xPluginIsEnabled: boolean}`
91-
An object with three properties. ```version``` is the version of MySQL used to create the database. ```versionIsInstalledOnSystem``` will be true if the MySQL version used is already installed on the system and false if the version had to be downloaded from MySQL's CDN. ```xPluginIsEnabled``` will be true if ```options.xEnabled``` is set to "FORCE", and will be false if ```options.xEnabled``` is set to "OFF".
90+
- `mysql: {version: string, versionIsInstalledOnSystem: boolean}`
91+
An object with three properties. ```version``` is the version of MySQL used to create the database. ```versionIsInstalledOnSystem``` will be true if the MySQL version used is already installed on the system and false if the version had to be downloaded from MySQL's CDN.
9292
- `stop: () => Promise<void>`
9393
The method to stop the database. The returned promise resolves when the database has successfully stopped.
9494

@@ -194,4 +194,4 @@ Description: The MySQL binary architecture to execute. MySQL does not offer serv
194194

195195
Default: "FORCE"
196196

197-
Description: This option follows the convention set out by the [MySQL Documentation](https://dev.mysql.com/doc/refman/en/plugin-loading.html). If set to "OFF", the MySQL X Plugin will not initialise. If set to "FORCE", the MySQL Server will not start up without a successful initialisation of the plugin, meaning that it's guaranteed the server will start up with MySQL X enabled. If the MySQL X initialisation fails, the server will not start up.
197+
Description: This option follows the convention set out by the [MySQL Documentation](https://dev.mysql.com/doc/refman/en/plugin-loading.html). If set to "OFF", the MySQL X Plugin will not initialise. If set to "FORCE", the MySQL Server will either start up with the MySQL X Plugin guaranteed to have successfully initialised, or if initialisation fails, the server will fail to start up.

dist/src/libraries/Version.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,26 @@ function getBinaryURL(versionToGet = "x", currentArch) {
8585
const minVersion = minVersions[0];
8686
throw `Your operating system is too out of date to run a version of MySQL that fits the following requirement: ${versionToGet}. The oldest version for your operating system that you would need to get a version that satisfies the version requirement is ${minVersion} but your current operating system is ${coercedOSRelease.version}. Please try changing your MySQL version requirement, updating your OS to a newer version, or if you believe this is a bug, please report this on GitHub.`;
8787
}
88-
if (process.platform === 'linux' && LinuxOSRelease_1.default.NAME === 'Ubuntu' && LinuxOSRelease_1.default.VERSION_ID >= '24.04') {
89-
//Since Ubuntu >= 24.04 uses libaio1t64 instead of libaio, this package has to copy libaio1t64 into a folder that MySQL looks in for dynamically linked libraries with the filename "libaio.so.1".
90-
//I have not been able to find a suitable folder for libaio1t64 to be copied into for MySQL < 8.0.4, so here we are filtering all versions lower than 8.0.4 since they fail to launch in Ubuntu 24.04.
91-
//If there is a suitable filepath for libaio1t64 to be copied into for MySQL < 8.0.4 then this check can be removed and these older MySQL versions can run on Ubuntu.
92-
//Pull requests are welcome for adding >= Ubuntu 24.04 support for MySQL < 8.0.4.
93-
//A way to get MySQL running on Ubuntu >= 24.04 is to symlink libaio1t64 to the location libaio would be. It is not suitable for this package to be doing that automatically, so instead this package has been copying libaio1t64 into the MySQL binary folder.
94-
selectedVersions = selectedVersions.filter(v => !(0, semver_1.lt)(v, '8.0.4'));
95-
}
96-
if (selectedVersions.length === 0) {
97-
throw `You are running a version of Ubuntu that is too modern to run any MySQL versions with this package that match the following version requirement: ${versionToGet}. Please choose a newer version of MySQL to use, or if you believe this is a bug please report this on GitHub.`;
88+
const isOnAlpineLinux = process.platform === 'linux' && LinuxOSRelease_1.default.NAME === 'Alpine Linux';
89+
if (process.platform === 'linux') {
90+
if (LinuxOSRelease_1.default.NAME === 'Ubuntu' && LinuxOSRelease_1.default.VERSION_ID >= '24.04') {
91+
//Since Ubuntu >= 24.04 uses libaio1t64 instead of libaio, this package has to copy libaio1t64 into a folder that MySQL looks in for dynamically linked libraries with the filename "libaio.so.1".
92+
//I have not been able to find a suitable folder for libaio1t64 to be copied into for MySQL < 8.0.4, so here we are filtering all versions lower than 8.0.4 since they fail to launch in Ubuntu 24.04.
93+
//If there is a suitable filepath for libaio1t64 to be copied into for MySQL < 8.0.4 then this check can be removed and these older MySQL versions can run on Ubuntu.
94+
//Pull requests are welcome for adding >= Ubuntu 24.04 support for MySQL < 8.0.4.
95+
//A way to get MySQL running on Ubuntu >= 24.04 is to symlink libaio1t64 to the location libaio would be. It is not suitable for this package to be doing that automatically, so instead this package has been copying libaio1t64 into the MySQL binary folder.
96+
selectedVersions = selectedVersions.filter(v => !(0, semver_1.lt)(v, '8.0.4'));
97+
if (selectedVersions.length === 0) {
98+
throw `You are running a version of Ubuntu that is too modern to run any MySQL versions with this package that match the following version requirement: ${versionToGet}. Please choose a newer version of MySQL to use, or if you believe this is a bug please report this on GitHub.`;
99+
}
100+
}
101+
else if (isOnAlpineLinux) {
102+
//https://github.com/Sebastian-Webster/mysql-server-musl-binaries only has support for v8.4.x and 9.x binaries
103+
selectedVersions = selectedVersions.filter(v => (0, semver_1.satisfies)(v, '8.4.x') || (0, semver_1.satisfies)(v, '9.x'));
104+
if (selectedVersions.length === 0) {
105+
throw 'mysql-memory-server has detected you are running this package on Alpine Linux. The source for MySQL with musl libc only provides binaries for MySQL 8.4.x and 9.x and as such only those versions can be used with this package. Please use 8.4.x or 9.x.';
106+
}
107+
}
98108
}
99109
//Sorts versions in descending order
100110
selectedVersions.sort((a, b) => a < b ? 1 : -1);
@@ -110,6 +120,9 @@ function getBinaryURL(versionToGet = "x", currentArch) {
110120
const macOSVersionNameKey = MySQLmacOSVersionNameKeys.find(range => (0, semver_1.satisfies)(selectedVersion, range));
111121
fileLocation = `${(0, semver_1.major)(selectedVersion)}.${(0, semver_1.minor)(selectedVersion)}/mysql-${selectedVersion}${isRC ? '-rc' : isDMR ? '-dmr' : ''}-${constants_1.MYSQL_MACOS_VERSIONS_IN_FILENAME[macOSVersionNameKey]}-${currentArch === 'x64' ? 'x86_64' : 'arm64'}.tar.gz`;
112122
}
123+
else if (isOnAlpineLinux) {
124+
fileLocation = `https://github.com/Sebastian-Webster/mysql-server-musl-binaries/releases/download/current/mysql-musl-${selectedVersion}-${currentArch === 'x64' ? 'x86_64' : 'arm64'}.tar.gz`;
125+
}
113126
else if (currentOS === 'linux') {
114127
const glibcObject = constants_1.MYSQL_LINUX_GLIBC_VERSIONS[currentArch];
115128
const glibcVersionKeys = Object.keys(glibcObject);
@@ -124,8 +137,12 @@ function getBinaryURL(versionToGet = "x", currentArch) {
124137
const fileExtension = constants_1.MYSQL_LINUX_FILE_EXTENSIONS[currentArch][fileExtensionKey];
125138
fileLocation = `${(0, semver_1.major)(selectedVersion)}.${(0, semver_1.minor)(selectedVersion)}/mysql-${selectedVersion}${isRC ? '-rc' : isDMR ? '-dmr' : ''}-linux-${minimalInstallAvailable !== 'no-glibc-tag' ? `glibc${glibcVersion}-` : ''}${currentArch === 'x64' ? 'x86_64' : 'aarch64'}${minimalInstallAvailable !== 'no' && (process.arch !== 'arm64' ? true : (0, semver_1.satisfies)(selectedVersion, constants_1.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64)) ? `-minimal${(0, semver_1.satisfies)(selectedVersion, constants_1.MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS) ? '-rebuild' : ''}` : ''}.tar.${fileExtension}`;
126139
}
140+
else {
141+
throw 'You are running this package on an unsupported OS. Please use either Windows, macOS, or a Linux-based OS.';
142+
}
127143
return {
128144
version: selectedVersion,
129-
url: constants_1.archiveBaseURL + fileLocation
145+
url: isOnAlpineLinux ? fileLocation : (constants_1.archiveBaseURL + fileLocation),
146+
hostedByOracle: !isOnAlpineLinux // Only the Alpine Linux binaries are not hosted on the MySQL CDN.
130147
};
131148
}

dist/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type DownloadedMySQLVersion = {
5858
export type BinaryInfo = {
5959
url: string;
6060
version: string;
61+
hostedByOracle: boolean;
6162
};
6263
export type OptionTypeChecks = {
6364
[key in keyof Required<ServerOptions>]: {

docs/SUPPORTED_MYSQL_DOWNLOADS.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
- Windows
99
- Linux
1010

11-
*```mysql-memory-server``` gets tested on Ubuntu 22.04 (x64 and arm64) and 24.04 (x64 and arm64), Fedora 41 (x64 and arm64) and 42 (x64 and arm64), macOS 13 (x64), 14 (arm64), and 15 (arm64), Windows 11 (arm64), and Windows Server 2022 (x64) and 2025 (x64). Linux distributions and Windows and macOS versions other than the ones tested may or may not work and are not guaranteed to work with this package.*
11+
*```mysql-memory-server``` gets tested on Ubuntu 22.04 (x64 and arm64) and 24.04 (x64 and arm64), Fedora 41 (x64 and arm64) and 42 (x64 and arm64), Alpine 3.22 (x64 and arm64), macOS 13 (x64), 14 (arm64), and 15 (arm64), Windows 11 (arm64), and Windows Server 2022 (x64) and 2025 (x64). Linux distributions and Windows and macOS versions other than the ones tested may or may not work and are not guaranteed to work with this package.*
1212

1313
## Binaries not available for download
1414

1515
- Versions 8.0.29, 8.0.38, 8.4.1, and 9.0.0 are not available for download for any operating systems as MySQL removed them from the CDN due to critical issues.
1616

1717
- Versions 5.7.32 - 5.7.44 are not available for download only for macOS systems as MySQL stopped supporting macOS Mojave starting from 5.7.32 for the rest of the 5.7.x line. As a result, those versions are not available for macOS in the MySQL CDN.
1818

19+
## Alpine Linux Limitations
20+
21+
Only MySQL versions 8.4.x and 9.x can be downloaded and ran with this package on Alpine Linux. The binaries for Alpine Linux are sourced from [Sebastian-Webster/mysql-server-musl-binaries](https://github.com/Sebastian-Webster/mysql-server-musl-binaries) on GitHub as Oracle does not support MySQL on musl-based Linux distributions. That repository only has support for MySQL 8.4.x and 9.x. If you discover any issues with MySQL (and not this package) when you are running this on Alpine Linux, please report the issue on that repository and not the ```mysql-memory-server``` one. The MySQL X Plugin is also not available when running on Alpine Linux due to compilation errors for musl.
22+
1923
## Native Binary Architectures
2024

2125
*Architectures used can be overridden by the ```arch``` option provided your OS and system supports running applications that use those architectures.*
@@ -56,7 +60,7 @@ Windows - No documented maximum version
5660

5761
macOS - No documented maximum version
5862

59-
Fedora Linux - No documented maximum version
63+
Fedora & Alpine Linux - No documented maximum version
6064

6165
Ubuntu Linux:
6266

@@ -86,4 +90,6 @@ Ubuntu Linux:
8690

8791
Fedora Linux: ```libaio1``` package and ```tar``` package
8892

89-
*Document last updated in v1.11.0*
93+
Alpine Linux: ```libstdc++``` package and ```libaio``` package
94+
95+
*Document last updated in v1.12.0*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"test": "jest --verbose --colors",
2020
"test:ci": "jest tests/ci --setupFilesAfterEnv ./ciSetup.js --verbose --colors",
21-
"os-compat:ci": "jest --setupFilesAfterEnv ./ciSetup.js --verbose --colors --runTestsByPath tests/versions.test.ts"
21+
"os-compat:ci": "jest tests/versions.test.ts --setupFilesAfterEnv ./ciSetup.js --verbose --colors"
2222
},
2323
"engines": {
2424
"node": ">=16.6.0",

src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
122122
} as const;
123123

124124
export const MIN_SUPPORTED_MYSQL = '5.7.19';
125-
export const downloadsBaseURL = 'https://cdn.mysql.com//Downloads/MySQL-'
126-
export const archiveBaseURL = 'https://cdn.mysql.com/archives/mysql-'
125+
export const MySQLCDNDownloadsBaseURL = 'https://cdn.mysql.com//Downloads/MySQL-'
126+
export const MySQLCDNArchivesBaseURL = 'https://cdn.mysql.com/archives/mysql-'
127127
// Versions 8.0.29, 8.0.38, 8.4.1, and 9.0.0 have been purposefully left out of this list as MySQL has removed them from the CDN due to critical issues.
128128
export const DOWNLOADABLE_MYSQL_VERSIONS = [
129129
'5.7.19', '5.7.20', '5.7.21', '5.7.22', '5.7.23', '5.7.24', '5.7.25', '5.7.26', '5.7.27', '5.7.28', '5.7.29', '5.7.30', '5.7.31', '5.7.32', '5.7.33', '5.7.34', '5.7.35', '5.7.36', '5.7.37', '5.7.38', '5.7.39', '5.7.40', '5.7.41', '5.7.42', '5.7.43', '5.7.44',

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BinaryInfo, InternalServerOptions, ServerOptions } from '../types'
55
import getBinaryURL from './libraries/Version'
66
import { downloadBinary } from './libraries/Downloader'
77
import { MIN_SUPPORTED_MYSQL, DEFAULT_OPTIONS_KEYS, OPTION_TYPE_CHECKS, DEFAULT_OPTIONS } from './constants'
8+
import etcOSRelease from './libraries/LinuxOSRelease'
89

910
export async function createDB(opts?: ServerOptions) {
1011
const suppliedOpts = opts || {};
@@ -41,7 +42,7 @@ export async function createDB(opts?: ServerOptions) {
4142
throw `A version of MySQL is installed on your system that is not supported by this package. If you want to download a MySQL binary instead of getting this error, please set the option "ignoreUnsupportedSystemVersion" to true.`
4243
}
4344

44-
logger.log('Version currently installed:', version)
45+
logger.log('Version currently installed:', version, 'Platform:', process.platform, 'etcOSRelease:', etcOSRelease)
4546
if (version === null || (options.version && !satisfies(version.version, options.version)) || unsupportedMySQLIsInstalled) {
4647
let binaryInfo: BinaryInfo;
4748
let binaryFilepath: string;
@@ -55,7 +56,7 @@ export async function createDB(opts?: ServerOptions) {
5556
}
5657

5758
logger.log('Running downloaded binary')
58-
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version, installedOnSystem: false})
59+
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version, installedOnSystem: false, xPluginSupported: binaryInfo.xPluginSupported})
5960
} else {
6061
logger.log(version)
6162
return await executor.startMySQL(options, version)

0 commit comments

Comments
 (0)