From 2d4384e7716c7e166ca0300a63a1e3cfd64d6fa3 Mon Sep 17 00:00:00 2001 From: Daniel Henkel <9447057+dhenkel92@users.noreply.github.com> Date: Sat, 4 May 2024 14:48:25 +0200 Subject: [PATCH] fix ci (#115) * fix ci * fix hetzner image deploy * remove temporal ci trigger --- .github/scripts/auth.sh | 5 --- .github/workflows/base-image.yml | 34 ++++++++-------- .github/workflows/consumer.yml | 33 +++++++-------- .github/workflows/react-frontend.yml | 30 +++++++------- .github/workflows/strapi.yml | 40 ++++++++----------- .../packer/manifests/basic_gameserver.pkr.hcl | 21 +++++----- .../01-game-cloud-platform/terraform.tfvars | 1 + 7 files changed, 77 insertions(+), 87 deletions(-) delete mode 100755 .github/scripts/auth.sh diff --git a/.github/scripts/auth.sh b/.github/scripts/auth.sh deleted file mode 100755 index 8c869a6..0000000 --- a/.github/scripts/auth.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/bash - -set -ex - -aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_ACCOUNT diff --git a/.github/workflows/base-image.yml b/.github/workflows/base-image.yml index daa680e..f238643 100644 --- a/.github/workflows/base-image.yml +++ b/.github/workflows/base-image.yml @@ -3,9 +3,9 @@ on: branches: - main paths: - - '.github/workflows/base-image.yml' - - 'infrastructure/packer/**/*' - - 'infrastructure/ansible/**/*' + - ".github/workflows/base-image.yml" + - "infrastructure/packer/**/*" + - "infrastructure/ansible/**/*" name: Base Image @@ -16,23 +16,25 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v2 - # fix backwards incompatibilities in template - - name: Fix Template - uses: hashicorp/packer-github-actions@master + - name: Setup `packer` + uses: hashicorp/setup-packer@main + id: setup with: - command: fix - target: infrastructure/packer/manifests/basic_gameserver.json - # validate templates - - name: Validate Template - uses: hashicorp/packer-github-actions@master - with: - command: validate - arguments: -syntax-only - target: infrastructure/packer/manifests/basic_gameserver.json + version: v1.10.3 + - name: Run `packer init` + id: init + working-directory: infrastructure/packer/ + run: "packer init ./manifests/basic_gameserver.pkr.hcl" + - name: Run `packer validate` + id: validate + working-directory: infrastructure/packer/ + run: "packer validate ./manifests/basic_gameserver.pkr.hcl" + env: + HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} # build artifact - name: Build Packer image working-directory: infrastructure/packer/ - run: packer build -color=false -on-error=abort -var-file ./vars/production.json ./manifests/basic_gameserver.json + run: packer build -color=false -on-error=abort -var-file ./vars/production.hcl ./manifests/basic_gameserver.pkr.hcl env: PACKER_LOG: 1h HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} diff --git a/.github/workflows/consumer.yml b/.github/workflows/consumer.yml index 0210acc..d65731e 100644 --- a/.github/workflows/consumer.yml +++ b/.github/workflows/consumer.yml @@ -3,15 +3,15 @@ on: branches: - main paths: - - '.github/workflows/consumer.yml' - - '.github/scripts/auth.sh' - - '.github/scripts/deploy.sh' - - 'async-server-provisioner/*' - - 'async-server-provisioner/*/*' - - 'async-server-provisioner/*/*/*' - - 'async-server-provisioner/*/*/*/*' - - 'async-server-provisioner/*/*/*/*/*' - - 'infrastructure/terraform/02-game-server/**/*' + - ".github/workflows/consumer.yml" + - ".github/scripts/auth.sh" + - ".github/scripts/deploy.sh" + - "async-server-provisioner/*" + - "async-server-provisioner/*/*" + - "async-server-provisioner/*/*/*" + - "async-server-provisioner/*/*/*/*" + - "async-server-provisioner/*/*/*/*/*" + - "infrastructure/terraform/02-game-server/**/*" name: Cloud Game Consumer @@ -20,17 +20,14 @@ jobs: name: Build Consumer runs-on: ubuntu-latest env: - IMAGE: 220002198733.dkr.ecr.eu-central-1.amazonaws.com/cloud-game/consumer + IMAGE: cloudgame/async-server-provisioner steps: - uses: actions/checkout@master - - name: Authenticate - # if: github.ref == 'refs/heads/main' - run: ./.github/scripts/auth.sh - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: eu-central-1 - ECR_ACCOUNT: 220002198733.dkr.ecr.eu-central-1.amazonaws.com + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build Docker Container run: | docker build -t $IMAGE:$GITHUB_RUN_ID -f async-server-provisioner/Dockerfile . diff --git a/.github/workflows/react-frontend.yml b/.github/workflows/react-frontend.yml index d861e0e..8eda353 100644 --- a/.github/workflows/react-frontend.yml +++ b/.github/workflows/react-frontend.yml @@ -3,14 +3,14 @@ on: branches: - main paths: - - '.github/workflows/react-frontend.yml' - - '.github/scripts/auth.sh' - - '.github/scripts/deploy.sh' - - 'react-frontend/*' - - 'react-frontend/*/*' - - 'react-frontend/*/*/*' - - 'react-frontend/*/*/*/*' - - 'react-frontend/*/*/*/*/*' + - ".github/workflows/react-frontend.yml" + - ".github/scripts/auth.sh" + - ".github/scripts/deploy.sh" + - "react-frontend/*" + - "react-frontend/*/*" + - "react-frontend/*/*/*" + - "react-frontend/*/*/*/*" + - "react-frontend/*/*/*/*/*" name: Cloud Game React Frontend @@ -19,16 +19,14 @@ jobs: name: Build React Frontend runs-on: ubuntu-latest env: - IMAGE: 220002198733.dkr.ecr.eu-central-1.amazonaws.com/cloud-game/react/frontend + IMAGE: cloudgame/frontend steps: - uses: actions/checkout@master - - name: Authenticate - run: ./.github/scripts/auth.sh - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: eu-central-1 - ECR_ACCOUNT: 220002198733.dkr.ecr.eu-central-1.amazonaws.com + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build Docker Container run: | cd react-frontend diff --git a/.github/workflows/strapi.yml b/.github/workflows/strapi.yml index 3f4a33d..8c09c75 100644 --- a/.github/workflows/strapi.yml +++ b/.github/workflows/strapi.yml @@ -3,10 +3,10 @@ on: branches: - main paths: - - '.github/workflows/strapi.yml' - - '.github/scripts/auth.sh' - - '.github/scripts/deploy.sh' - - 'backend/**/*' + - ".github/workflows/strapi.yml" + - ".github/scripts/auth.sh" + - ".github/scripts/deploy.sh" + - "backend/**/*" name: Cloud Game Backend Strapi @@ -15,17 +15,14 @@ jobs: name: Build Strapi API runs-on: ubuntu-latest env: - IMAGE: 220002198733.dkr.ecr.eu-central-1.amazonaws.com/cloud-game/strapi/backend + IMAGE: cloudgame/backend-api steps: - uses: actions/checkout@master - - name: Authenticate - # if: github.ref == 'refs/heads/main' - run: ./.github/scripts/auth.sh - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: eu-central-1 - ECR_ACCOUNT: 220002198733.dkr.ecr.eu-central-1.amazonaws.com + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build Docker Container run: | docker build -t $IMAGE:$GITHUB_RUN_ID -f backend/Dockerfile-prod-be . @@ -39,23 +36,20 @@ jobs: name: Build Strapi Frontend runs-on: ubuntu-latest env: - IMAGE: 220002198733.dkr.ecr.eu-central-1.amazonaws.com/cloud-game/strapi/frontend + IMAGE: cloudgame/backend-admin steps: - uses: actions/checkout@master - - name: Authenticate - # if: github.ref == 'refs/heads/main' - run: ./.github/scripts/auth.sh - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: eu-central-1 - ECR_ACCOUNT: 220002198733.dkr.ecr.eu-central-1.amazonaws.com + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build Docker Container run: | cd backend docker build -t $IMAGE:$GITHUB_RUN_ID -f Dockerfile-prod-fe --build-arg ADMIN_URL=${ADMIN_URL} --build-arg SERVER_URL=${SERVER_URL} . env: - ADMIN_URL: https://admin.cloud-game.app/ + ADMIN_URL: / SERVER_URL: https://api.cloud-game.app/ - name: Push Container run: | diff --git a/infrastructure/packer/manifests/basic_gameserver.pkr.hcl b/infrastructure/packer/manifests/basic_gameserver.pkr.hcl index 81e8ff1..e97623e 100644 --- a/infrastructure/packer/manifests/basic_gameserver.pkr.hcl +++ b/infrastructure/packer/manifests/basic_gameserver.pkr.hcl @@ -8,27 +8,30 @@ packer { } variable "base_image" { - type = string + type = string + default = "debian-11" } variable "server_type" { - type = string + type = string + default = "cx11" } variable "location" { - type = string + type = string + default = "nbg1" } source "hcloud" "basic_gameserver" { communicator = "ssh" - image = var.base_image - location = var.location - server_type = var.server_type - ssh_username = "root" + image = var.base_image + location = var.location + server_type = var.server_type + ssh_username = "root" snapshot_name = "basic-gameserver-{{timestamp}}" snapshot_labels = { - "application": "basic-gameserver" + "application" : "basic-gameserver" } } @@ -36,7 +39,7 @@ build { sources = ["hcloud.basic_gameserver"] provisioner "file" { - source = "../ansible" + source = "../ansible" destination = "/tmp/ansible" } diff --git a/infrastructure/terraform/01-game-cloud-platform/terraform.tfvars b/infrastructure/terraform/01-game-cloud-platform/terraform.tfvars index 6e63376..3d128fa 100644 --- a/infrastructure/terraform/01-game-cloud-platform/terraform.tfvars +++ b/infrastructure/terraform/01-game-cloud-platform/terraform.tfvars @@ -20,6 +20,7 @@ dns = { "cloud-game.app", "api.cloud-game.app", "admin.cloud-game.app", + "ext.cloud-game.app", ] }