Skip to content

Commit

Permalink
Automtically install MySql in devcontainer for use by existing Go uni…
Browse files Browse the repository at this point in the history
…t tests.

TESTED by building the devcontainer, following setup instructions from README and finally running `make test`.
  • Loading branch information
alexsapps committed Mar 25, 2024
1 parent e266a77 commit c53a70c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mcr.microsoft.com/devcontainers/base:bullseye

# Install MySql for Go backend unit tests. The tests expect MySql to be
# installed directly in the development environment rather than in another
# docker continer such as the dev database used for manual testing.
COPY install-mysql.sh .
RUN chmod +x ./install-mysql.sh && ./install-mysql.sh
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
"name": "Debian",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"name": "DxE ADB",
"build": {
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
Expand Down
31 changes: 31 additions & 0 deletions .devcontainer/install-mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Original: https://gist.github.com/soubrunorocha/ec30b7704d737a1797b0281e97967834

# Fail if any line fails and return an error so that building this Dockerfile
# will not swallow the script's errors.
set -e

#set the root password
DEFAULTPASS=""

#set some config to avoid prompting
sudo debconf-set-selections <<EOF
mysql-community-server mysql-community-server/root-pass password $DEFAULTPASS
mysql-community-server mysql-community-server/re-root-pass password $DEFAULTPASS
EOF

#get the mysql repository via wget
wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb

#set debian frontend to not prompt
export DEBIAN_FRONTEND=noninteractive

#config the package
sudo -E dpkg -i mysql-apt-config_0.8.29-1_all.deb

#update apt to get mysql repository
sudo apt update

#install mysql according to previous config
sudo -E apt install mysql-server mysql-client --assume-yes --force-yes

rm mysql-apt-config_0.8.29-1_all.deb

0 comments on commit c53a70c

Please sign in to comment.