You'll be leveraging Docker and Kubernetes, which are excellent choices for containerization and orchestration, respectively. Here's a high-level guide on how you might achieve this, focused on your RPGJS project with Agones for game server management.
- Ensure you have a GitHub repository for your RPGJS project. Use Github Actions: https://github.com/features/actions
- Dockerfile configured in your project root (for containerization).
- Kubernetes configuration files (YAML) for deploying your application, including separate configurations for dev and production if necessary.
- A Kubernetes cluster set up, possibly with Agones installed if you're using it for game server management.
- Access to a domain and the ability to configure subdomains (for
www.myDomain.com
and www.myDomain.com/testing
).
Setting Up GitHub Actions Workflows
You'll create two main workflows in the .github/workflows
directory of your project: one for development (dev.yml
) and another for production (prod.yml
).
Development Workflow (dev.yml
)
- Trigger: Set the workflow to trigger on pushes to the
dev
branch.
name: Deploy to Development
on:
push:
branches:
- dev
- Build and Push Docker Image: Add steps to build your Docker image and push it to a container registry (e.g., GitHub Packages or Docker Hub).
Dockerfile: https://docs.rpgjs.dev/guide/production.html
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-registry/rpg:dev-${{ github.sha }}
- name: Push the Docker image
run: docker push my-registry/rpg:dev-${{ github.sha }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up kubectl
uses: actions-hub/kubectl@master
with:
version: 'latest' # It's better to specify a fixed version of kubectl for consistency
- name: Apply Kubernetes configuration
run: kubectl apply -f deployment-prod.yml
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
Production Workflow (prod.yml
)
Follow a similar structure for the production workflow, but trigger it on pushes to the prod
branch and ensure it deploys using your production Kubernetes configurations. Additionally, make sure public registrations are enabled in this environment.
Warning: in production, if you update the game server, you lose all current states. So remember to make a snapshot in a Redis, for example, to keep track of player progress 🙂