From d84913d98aa5e13f6677a40886944b08de18d067 Mon Sep 17 00:00:00 2001 From: rajdip-b Date: Mon, 27 May 2024 10:59:21 +0530 Subject: [PATCH] ci: Replace fly deployment with AWS --- .github/workflows/release-api.yml | 28 ------------------------- .github/workflows/release-web.yml | 35 ++++++++++++++++++++++--------- .github/workflows/stage-web.yml | 20 ------------------ fly.api.toml | 33 ----------------------------- fly.web.toml | 23 -------------------- 5 files changed, 25 insertions(+), 114 deletions(-) delete mode 100644 .github/workflows/release-api.yml delete mode 100644 .github/workflows/stage-web.yml delete mode 100644 fly.api.toml delete mode 100644 fly.web.toml diff --git a/.github/workflows/release-api.yml b/.github/workflows/release-api.yml deleted file mode 100644 index bd90f40d..00000000 --- a/.github/workflows/release-api.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: - push: - branches: - - main - tags: - - '*' - -jobs: - build-api-release: - runs-on: ubuntu-latest - name: Build and push API docker image for release - if: ${{ startsWith(github.ref , 'refs/tags/')}} - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build Docker image - run: docker build -t keyshade/keyshade-api:${{ github.ref_name }} keyshade/keyshade-api:latest -f ./apps/api/Dockerfile . - - - name: Push Docker image - run: docker push keyshade/keyshade-api diff --git a/.github/workflows/release-web.yml b/.github/workflows/release-web.yml index 2e3b50e3..fc8317a4 100644 --- a/.github/workflows/release-web.yml +++ b/.github/workflows/release-web.yml @@ -2,27 +2,42 @@ on: push: branches: - main - tags: - - '*' jobs: build-web-release: runs-on: ubuntu-latest + environment: alpha name: Build and push Web docker image for release - if: ${{ startsWith(github.ref , 'refs/tags/') }} steps: - name: Checkout uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v1 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + aws-access-key-id: ${{ secrets.ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.SECRET_KEY }} + aws-region: ap-south-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 - name: Build Docker image - run: docker build -t keyshade/keyshade-web:${{ github.ref_name }} keyshade/keyshade-web:latest -f ./apps/web/Dockerfile . + id: build + env: + ECR_REGISTRY: ${{ vars.ECR_REGISTRY }} + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} + run: | + # Build a docker container and push it to ECR + aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin $ECR_REGISTRY + docker build -t keyshade/keyshade-web:alpha-${GITHUB_SHA::6} $ECR_REGISTRY/$ECR_REPOSITORY:latest -f ./apps/web/Dockerfile . + echo "Pushing image to ECR..." + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest + echo "name=image::$ECR_REGISTRY/$ECR_REPOSITORY:latest" >> $GITHUB_OUTPUT - - name: Push Docker image - run: docker push keyshade/keyshade-web + - name: Force re-deploy task in service + id: force-redeploy + run: | + aws ecs update-service --cluster shaer-stage-cluster --service backend-stage-service --force-new-deployment diff --git a/.github/workflows/stage-web.yml b/.github/workflows/stage-web.yml deleted file mode 100644 index 54536a9e..00000000 --- a/.github/workflows/stage-web.yml +++ /dev/null @@ -1,20 +0,0 @@ -on: - push: - branches: - - develop - paths: ['apps/web/**', '.github/workflows/stage-web.yml', 'fly.web.toml'] - -jobs: - deploy-stage: - runs-on: ubuntu-latest - name: Deploy to stage - if: github.ref == 'refs/heads/develop' - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install fly CLI - run: | - curl -L https://fly.io/install.sh | sh - - name: Deploy to stage - run: ~/.fly/bin/fly deploy --config fly.web.toml --dockerfile ./apps/web/Dockerfile --app keyshade-web --access-token ${{ secrets.FLY_ACCESS_TOKEN }} diff --git a/fly.api.toml b/fly.api.toml deleted file mode 100644 index bf6b3b3b..00000000 --- a/fly.api.toml +++ /dev/null @@ -1,33 +0,0 @@ -primary_region = "bom" - -[http_service] - internal_port = 4200 - force_https = true - auto_stop_machines = true - auto_start_machines = true - min_machines_running = 0 - [http_service.concurrency] - type = "requests" - soft_limit = 200 - hard_limit = 250 - -[http_service.tls_options] - alpn = ["h2", "http/1.1"] - versions = ["TLSv1.2", "TLSv1.3"] - default_self_signed = true - -[[http_service.checks]] - grace_period = "10s" - interval = "30s" - method = "GET" - timeout = "10s" - path = "/api/health" - protocol = "http" - port = 4200 - tls_skip_verify = true - -[[vm]] - size = "shared-cpu-1x" - memory = "512mb" - cpus = 1 - cpu_kind = "shared" diff --git a/fly.web.toml b/fly.web.toml deleted file mode 100644 index 740a3056..00000000 --- a/fly.web.toml +++ /dev/null @@ -1,23 +0,0 @@ -primary_region = "bom" - -[http_service] - internal_port = 3000 - force_https = true - auto_stop_machines = true - auto_start_machines = true - min_machines_running = 0 - [http_service.concurrency] - type = "requests" - soft_limit = 200 - hard_limit = 250 - -[http_service.tls_options] - alpn = ["h2", "http/1.1"] - versions = ["TLSv1.2", "TLSv1.3"] - default_self_signed = true - -[[vm]] - size = "shared-cpu-1x" - memory = "512mb" - cpus = 1 - cpu_kind = "shared"