|
| 1 | +name: Build and Push Flutter Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'Dockerfile' |
| 9 | + - '.github/workflows/build-push.yml' |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + flutter_version: |
| 13 | + description: 'Flutter version to build (leave empty to use Dockerfile default)' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + |
| 17 | +env: |
| 18 | + REGISTRY: ghcr.io |
| 19 | + IMAGE_NAME: opsdev-ws/flutter |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Extract Flutter version from Dockerfile |
| 33 | + id: version |
| 34 | + run: | |
| 35 | + if [ -n "${{ inputs.flutter_version }}" ]; then |
| 36 | + VERSION="${{ inputs.flutter_version }}" |
| 37 | + else |
| 38 | + VERSION=$(grep -m1 'ARG flutter_ver=' Dockerfile | cut -d'=' -f2) |
| 39 | + fi |
| 40 | + echo "flutter_version=${VERSION}" >> $GITHUB_OUTPUT |
| 41 | + echo "Building Flutter version: ${VERSION}" |
| 42 | +
|
| 43 | + - name: Set up QEMU |
| 44 | + uses: docker/setup-qemu-action@v3 |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v3 |
| 48 | + |
| 49 | + - name: Log in to GitHub Container Registry |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Extract metadata |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@v5 |
| 59 | + with: |
| 60 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 61 | + tags: | |
| 62 | + type=raw,value=${{ steps.version.outputs.flutter_version }} |
| 63 | + type=raw,value=latest |
| 64 | +
|
| 65 | + - name: Build and push multi-arch image |
| 66 | + uses: docker/build-push-action@v5 |
| 67 | + with: |
| 68 | + context: . |
| 69 | + platforms: linux/amd64,linux/arm64 |
| 70 | + push: true |
| 71 | + tags: ${{ steps.meta.outputs.tags }} |
| 72 | + labels: ${{ steps.meta.outputs.labels }} |
| 73 | + cache-from: type=gha |
| 74 | + cache-to: type=gha,mode=max |
| 75 | + build-args: | |
| 76 | + flutter_ver=${{ steps.version.outputs.flutter_version }} |
0 commit comments