|
| 1 | +name: Container Image |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 'main' |
| 6 | + tags: |
| 7 | + - '**' |
| 8 | + |
| 9 | +env: |
| 10 | + alpine_version: '3.17' |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build container image and push it to registry |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + id-token: write |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: Login to Docker Hub |
| 25 | + uses: docker/login-action@v2 |
| 26 | + with: |
| 27 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 28 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 29 | + |
| 30 | + - name: Login to GitHub Container Registry |
| 31 | + uses: docker/login-action@v2 |
| 32 | + with: |
| 33 | + registry: ghcr.io |
| 34 | + username: ${{ github.actor }} |
| 35 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - name: Configure AWS credentials |
| 38 | + uses: aws-actions/configure-aws-credentials@v1 |
| 39 | + with: |
| 40 | + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} |
| 41 | + aws-region: us-east-1 |
| 42 | + |
| 43 | + - name: Login to Amazon ECR Public |
| 44 | + id: login-ecr-public |
| 45 | + uses: aws-actions/amazon-ecr-login@v1 |
| 46 | + with: |
| 47 | + registry-type: public |
| 48 | + |
| 49 | + - name: Parse version |
| 50 | + id: get-version |
| 51 | + uses: battila7/get-version-action@v2 |
| 52 | + |
| 53 | + - name: Set up QEMU |
| 54 | + uses: docker/setup-qemu-action@v2 |
| 55 | + |
| 56 | + - name: Set up Docker Buildx |
| 57 | + uses: docker/setup-buildx-action@v2 |
| 58 | + |
| 59 | + - name: Build and push - testing |
| 60 | + uses: docker/build-push-action@v3 |
| 61 | + if: ${{ !steps.get-version.outputs.is-semver }} |
| 62 | + with: |
| 63 | + context: . |
| 64 | + file: ./Dockerfile |
| 65 | + platforms: linux/amd64,linux/arm64 |
| 66 | + push: true |
| 67 | + build-args: | |
| 68 | + ALPINE_VERSION=${{ env.alpine_version }} |
| 69 | + tags: | |
| 70 | + cookielab/alpine:${{ github.ref_name }} |
| 71 | + public.ecr.aws/cookielab/alpine:${{ github.ref_name }} |
| 72 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }} |
| 73 | + |
| 74 | + - name: Build and push - pre-release |
| 75 | + uses: docker/build-push-action@v3 |
| 76 | + if: ${{ steps.get-version.outputs.is-semver && steps.get-version.outputs.prerelease != '' }} |
| 77 | + with: |
| 78 | + context: . |
| 79 | + file: ./Dockerfile |
| 80 | + platforms: linux/amd64,linux/arm64 |
| 81 | + push: true |
| 82 | + build-args: | |
| 83 | + ALPINE_VERSION=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }} |
| 84 | + tags: | |
| 85 | + cookielab/alpine:${{ steps.get-version.outputs.version-without-v }} |
| 86 | + public.ecr.aws/cookielab/alpine:${{ steps.get-version.outputs.version-without-v }} |
| 87 | + ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.version-without-v }} |
| 88 | + |
| 89 | + - name: Build and push - stable |
| 90 | + uses: docker/build-push-action@v3 |
| 91 | + if: ${{ steps.get-version.outputs.is-semver && steps.get-version.outputs.prerelease == '' }} |
| 92 | + with: |
| 93 | + context: . |
| 94 | + file: ./Dockerfile |
| 95 | + platforms: linux/amd64,linux/arm64 |
| 96 | + push: true |
| 97 | + build-args: | |
| 98 | + ALPINE_VERSION=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }} |
| 99 | + tags: | |
| 100 | + cookielab/alpine:${{ steps.get-version.outputs.version-without-v }} |
| 101 | + cookielab/alpine:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }} |
| 102 | + cookielab/alpine:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }} |
| 103 | + cookielab/alpine:${{ steps.get-version.outputs.major }} |
| 104 | + public.ecr.aws/cookielab/alpine:${{ steps.get-version.outputs.version-without-v }} |
| 105 | + public.ecr.aws/cookielab/alpine:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }} |
| 106 | + public.ecr.aws/cookielab/alpine:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }} |
| 107 | + public.ecr.aws/cookielab/alpine:${{ steps.get-version.outputs.major }} |
| 108 | + ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.version-without-v }} |
| 109 | + ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }} |
| 110 | + ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }} |
| 111 | + ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.major }} |
0 commit comments