Docker - NextJS Hello App by @tj-boyle from main #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker - NextJS Hello App | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
## GitHub Actions need '**' to match branches with '/' in their name | |
- '**' | |
paths: | |
- "nextjs/hello-app/**" | |
tags: | |
- '*' | |
pull_request: | |
branches: | |
- 'main' | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
defaults: | |
run: | |
shell: bash | |
run-name: ${{ github.workflow }} by @${{ github.actor }} from ${{ github.ref_name }} | |
jobs: | |
build: | |
name: Build and Push Image | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_REGISTRY: ghcr.io | |
DOCKER_IMAGE_NAME: deptagency/nextjs-hello-app | |
steps: | |
- | |
name: Check out code | |
uses: actions/checkout@v3 | |
- | |
name: AWS Login | |
uses: ./.github/actions/aws-login | |
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: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Docker meta | |
id: dockermeta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }} | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Build Tag and Push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
file: nextjs/hello-app/docker/Dockerfile | |
context: nextjs/hello-app | |
tags: ${{ steps.dockermeta.outputs.tags }} | |
# tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:latest | |
labels: ${{ steps.dockermeta.outputs.labels }} | |
push: true | |
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:dockercache | |
cache-to: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:dockercache,mode=max,image-manifest=true | |
- | |
name: Deploy to Amazon ECS | |
run: | | |
echo "Deploying to cluster" | |
aws ecs update-service --cluster jirawat-cognito-demo --service nextjs-hw-srv-03 --force-new-deployment --task-definition nextjs-hello-world --region us-east-1 | |
aws ecs wait services-stable --cluster jirawat-cognito-demo --service nextjs-hw-srv-03 --region us-east-1 | |
shell: bash |