diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a01f445..eeb7c0cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,15 +1,9 @@ name: Sharingan Build on: - push: - branches: [ main ] - paths-ignore: - - '**/.md' pull_request: branches: [ main ] paths-ignore: - '**/.md' -env: - COMMIT_SHA: ${{ github.event.pull_request.head.sha }} concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -51,21 +45,3 @@ jobs: - name: Run tests run: yarn test - - trigger_deploy: - if: ${{ github.ref == 'refs/heads/main' }} - name: trigger_deploy - needs: [ build ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Trigger deployment - run: | - set -e - - GITHUB_TOKEN=${{ github.token }} - SHA=${COMMIT_SHA:=latest} - - echo $SHA - - curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/tericcabrel/sharingan/actions/workflows/deploy-core.yml/dispatches -d '{"ref": "main", "inputs": {"commit-sha": "'"$SHA"'"}}' diff --git a/.github/workflows/deploy-core.yml b/.github/workflows/deploy-core.yml index 19c28058..13305ccf 100644 --- a/.github/workflows/deploy-core.yml +++ b/.github/workflows/deploy-core.yml @@ -1,43 +1,46 @@ name: Sharingan Deploy Core on: - workflow_dispatch: - inputs: - commit-sha: - description: "SHA of the latest commit in the pull request" - required: true + pull_request: + branches: + - main + push: + branches: + - main + - dev + paths: + - 'apps/core/src/**' env: - IMAGE_TAG: tericcabrel/sharingan-core:${{ github.event.inputs.commit-sha }} + IMAGE_TAG: ${{ github.sha }} jobs: - package: + package-ecr: runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} steps: - uses: actions/checkout@v2 - - name: Copy the core Dockerfile in the root repository - run: cp apps/core/Dockerfile . - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 + - name: Login to Amazon ECR + id: ecr-login + uses: aws-actions/amazon-ecr-login@v1 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry-type: public - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ env.IMAGE_TAG }} + - name: Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: public.ecr.aws/x9y5g9l2 + REPOSITORY: sharingan + run: | + aws ecr-public get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $REGISTRY + docker build -t sharingan-core:$IMAGE_TAG . + docker tag sharingan-core:$IMAGE_TAG $REGISTRY/sharingan-core:$IMAGE_TAG + docker push $REGISTRY/sharingan-core:$IMAGE_TAG deploy: + if: false defaults: run: working-directory: apps/core