diff --git a/.github/workflows/files/demo-production-task-definition.json b/.github/workflows/files/demo-production-task-definition.json new file mode 100644 index 0000000..a03f615 --- /dev/null +++ b/.github/workflows/files/demo-production-task-definition.json @@ -0,0 +1,35 @@ +{ + "containerDefinitions": [ + { + "name": "demo", + "image": "howdi/chatkitty-demo:latest", + "cpu": 0, + "memoryReservation": 128, + "portMappings": [ + { + "containerPort": 80, + "hostPort": 0, + "protocol": "tcp" + } + ], + "essential": true, + "environment": [], + "mountPoints": [], + "volumesFrom": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "awslogs-chatkitty-production", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "demo" + } + } + } + ], + "family": "chatkitty-demo", + "taskRoleArn": "arn:aws:iam::785157241395:role/dev-docker-task", + "networkMode": "bridge", + "volumes": [], + "placementConstraints": [], + "requiresCompatibilities": [] +} diff --git a/.github/workflows/files/demo-staging-task-definition.json b/.github/workflows/files/demo-staging-task-definition.json new file mode 100644 index 0000000..effa16f --- /dev/null +++ b/.github/workflows/files/demo-staging-task-definition.json @@ -0,0 +1,35 @@ +{ + "containerDefinitions": [ + { + "name": "demo", + "image": "howdi/chatkitty-demo:latest", + "cpu": 0, + "memoryReservation": 128, + "portMappings": [ + { + "containerPort": 80, + "hostPort": 0, + "protocol": "tcp" + } + ], + "essential": true, + "environment": [], + "mountPoints": [], + "volumesFrom": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "awslogs-chatkitty-staging", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "demo" + } + } + } + ], + "family": "chatkitty-staging-demo", + "taskRoleArn": "arn:aws:iam::785157241395:role/dev-docker-task", + "networkMode": "bridge", + "volumes": [], + "placementConstraints": [], + "requiresCompatibilities": [] +} diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml new file mode 100644 index 0000000..2ee293e --- /dev/null +++ b/.github/workflows/release-production.yml @@ -0,0 +1,81 @@ +name: Release (Production) + +on: + push: + tags: + - 'v*.*.*' + +env: + AWS_REGION: us-east-1 + ECS_CLUSTER: howdi + DEMO_ECS_SERVICE: chatkitty-demo + DEMO_CONTAINER_NAME: demo + DEMO_ECS_TASK_DEFINITION: .github/workflows/files/demo-production-task-definition.json + +jobs: + release-demo: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Use Node 16.x + uses: actions/setup-node@v2 + with: + node-version: '16.x' + cache: 'yarn' + cache-dependency-path: yarn.lock + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - 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: ${{ env.AWS_REGION }} + + - name: Build React application + run: | + yarn install --frozen-lockfile; + yarn run build; + + - name: Generate image tags + id: image-tags + run: | + echo "::set-output name=release-version-tag::$(git rev-parse --short HEAD)"; + echo "::set-output name=image-tag::howdi/chatkitty-website:$(git describe --tags)"; + + - name: Build and push Docker image + id: docker-build + uses: docker/build-push-action@v2 + with: + file: ./docker/Dockerfile + push: true + tags: ${{ steps.image-tags.outputs.image-tag }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} + + - name: Fill out ECS task definition + id: task-definition + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: ${{ env.DEMO_ECS_TASK_DEFINITION }} + container-name: ${{ env.DEMO_CONTAINER_NAME }} + image: ${{ steps.image-tags.outputs.image-tag }} + + - name: Deploy ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-definition.outputs.task-definition }} + service: ${{ env.DEMO_ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml new file mode 100644 index 0000000..051c638 --- /dev/null +++ b/.github/workflows/release-staging.yml @@ -0,0 +1,74 @@ +name: Release (Staging) + +on: + push: + branches: [ main ] + +env: + AWS_REGION: us-east-1 + ECS_CLUSTER: howdi-dev + DEMO_ECS_SERVICE: chatkitty-staging-demo + DEMO_CONTAINER_NAME: demo + DEMO_IMAGE_TAG: howdi/chatkitty-demo:latest + DEMO_ECS_TASK_DEFINITION: .github/workflows/files/demo-staging-task-definition.json + +jobs: + release-demo: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Use Node 16.x + uses: actions/setup-node@v2 + with: + node-version: '16.x' + cache: 'yarn' + cache-dependency-path: yarn.lock + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - 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: ${{ env.AWS_REGION }} + + - name: Build React application + run: | + yarn install --frozen-lockfile; + yarn run build; + + - name: Build and push Docker image + id: docker-build + uses: docker/build-push-action@v2 + with: + file: ./docker/Dockerfile + push: true + tags: ${{ env.DEMO_IMAGE_TAG }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} + + - name: Fill out ECS task definition + id: task-definition + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: ${{ env.DEMO_ECS_TASK_DEFINITION }} + container-name: ${{ env.DEMO_CONTAINER_NAME }} + image: ${{ env.DEMO_IMAGE_TAG }} + + - name: Deploy ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-definition.outputs.task-definition }} + service: ${{ env.DEMO_ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }}