Skip to content

epomatti/aws-github-runner-migrations

Repository files navigation

AWS GitHub Self-Hosted Runners Migrations

Deploying GitHub self-hosted runners to apply migrations to AWS RDS for MySQL.

Architecture overview:

Setup

Create the .auto.tfvars from the template:

cp samples/sample.tfvars .auto.tfvars

Create the infrastructure:

terraform init
terraform apply -auto-approve

GitHub Runner

Connect to the GitHub Runner host.

aws ssm start-session --target i-00000000000000000

If creating a new environment, verify that the userdata executed correctly and reboot to apply kernel upgrades:

Should reboot automatically

cloud-init status

Switch to root:

sudo su -

Enter the /opt directory, this is where we'll install the runner agent:

cd /opt

Enable the runner scripts to run as root:

export RUNNER_ALLOW_RUNASROOT="1"

Access the repository Actions section and create a new runner.

Make sure you select the appropriate architecture, which should be Linux and ARM64.

Once done, stop the agent and install the runner agent as a service:

./svc.sh install
./svc.sh start
./svc.sh status

GitHub Action

This repository contains examples of pipelines in the .github/workflows directory.

Check out the guidelines for Prisma migrations deployment, or for your preferred migration tool.

Local development

Start bu running a MySQL instance:

docker run -d \
    -e MYSQL_DATABASE=mysqldb \
    -e MYSQL_ROOT_PASSWORD=cxvxc2389vcxzv234r \
    -p 3306:3306 \
    --name mysql-prisma-local \
    mysql:8.0

Special privileges are required by Prisma to apply shadow databases.

Enter the application directory:

cd app

Apply the migrations:

Whenever you update your Prisma schema, you will have to update your database schema using either prisma migrate dev or prisma db push. This will keep your database schema in sync with your Prisma schema. The commands will also regenerate Prisma Client.

# This calls generate under the hood
npx prisma migrate dev --name init

Run the application locally:

npm run dev

Check if the schema and database connections are working:

curl localhost:3000/prisma

Docker image

To verify that the Docker image,

docker compose up

Add the DATABASE_URL environment variable:

export DATABASE_URL='mysql://root:cxvxc2389vcxzv234r@localhost:3306/mysqldb'

Deploy the migration:

npx prisma migrate deploy