|
| 1 | +name: WORK_FLOW_CREATE_CONTAINER |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + stageName: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + imageName: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + PROJECT_NAME: icasu-ecs-fargate |
| 15 | + CACHE_PATH: /tmp/.buildx-cache-icasu-ecs-fargate-sample-app |
| 16 | + |
| 17 | +permissions: |
| 18 | + id-token: write |
| 19 | + contents: read |
| 20 | + actions: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + create-container: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 30 |
| 26 | + environment: ${{ inputs.stageName }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v4 |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + - name: Cache Docker layers |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: ${{ env.CACHE_PATH }} |
| 37 | + key: ${{ runner.os }}-${{ env.CACHE_PATH }}-${{ github.sha }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-${{ env.CACHE_PATH }} |
| 40 | + - name: Create tag |
| 41 | + run: | |
| 42 | + COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") |
| 43 | + TAG=${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-1.amazonaws.com/${{ inputs.imageName }}:$COMMIT_HASH |
| 44 | + echo "TAGS=$TAG" >> $GITHUB_ENV |
| 45 | + - name: Configure AWS credentials |
| 46 | + uses: aws-actions/configure-aws-credentials@v4 |
| 47 | + with: |
| 48 | + role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/${{ env.PROJECT_NAME }}-assume-role |
| 49 | + aws-region: ap-northeast-1 |
| 50 | + - name: Login to Amazon ECR |
| 51 | + uses: aws-actions/amazon-ecr-login@v2 |
| 52 | + - name: Build and push |
| 53 | + uses: docker/build-push-action@v6 |
| 54 | + with: |
| 55 | + context: . |
| 56 | + tags: ${{ env.TAGS }} |
| 57 | + push: true |
| 58 | + platforms: linux/amd64 |
| 59 | + file: Dockerfile.server |
| 60 | + provenance: false |
| 61 | + cache-from: type=local,src=${{ env.CACHE_PATH }} |
| 62 | + cache-to: type=local,dest=${{ env.CACHE_PATH }}-new,mode=max |
| 63 | + - name: Move cache |
| 64 | + run: | |
| 65 | + rm -rf ${{ env.CACHE_PATH }} |
| 66 | + mv ${{ env.CACHE_PATH }}-new ${{ env.CACHE_PATH }} |
0 commit comments