diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8c1ff77..a7bbb2d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,46 +17,34 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Get Version id: get_version uses: battila7/get-version-action@v2.0.0 - - name: Build, tag, and push image to Amazon ECR - id: build-image + - name: Build container image env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: prepbot IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest - echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" - - - name: Fill in the new image ID in the Amazon ECS task definition - id: task-def - uses: aws-actions/amazon-ecs-render-task-definition@v1 - with: - task-definition: task-definition.json - container-name: "prepbot" - image: ${{ steps.build-image.outputs.image }} + run: docker build -t registry.digitalocean.com/djpianalto/prepbot:$IMAGE_TAG . - - name: Deploy Amazon ECS task definition - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + - name: Install doctl + uses: digitalocean/action-doctl@v2 with: - task-definition: ${{ steps.task-def.outputs.task-definition }} - service: "prepbot" - cluster: "discord-bots" - wait-for-service-stability: true + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Login to DigitalOcean Container Registry with short-lived credentials + run: doctl registry login --expiry-seconds 600 + + - name: Push image to DigitalOcean Container Registry + run: docker push registry.digitalocean.com/djpianalto/prepbot + + - name: Update deployment file + run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's||registry.digitalocean.com/djpianalto/prepbot:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml + + - name: Save DigitalOcean kubeconfig with short-lived credentials + run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 discord-bots + + - name: Deploy to DigitalOcean Kubernetes + run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml + + - name: Verify deployment + run: kubectl rollout status deployment/prepbot diff --git a/deployment.yml b/deployment.yml new file mode 100644 index 0000000..0ee3ae8 --- /dev/null +++ b/deployment.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prepbot + namespace: default + labels: + app: prepbot +spec: + replicas: 1 + selector: + matchLabels: + app: prepbot + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + minReadySeconds: 120 + template: + metadata: + labels: + app: prepbot + spec: + containers: + - name: prepbot + image: + env: + - name: DISCORD_TOKEN + valueFrom: + secretKeyRef: + name: prepbot + key: discord_token