弹性豆茎对接机的Flutter腹板CICD持续失效

xxls0lw8  于 2023-03-31  发布在  Flutter
关注(0)|答案(1)|浏览(88)

我一直试图在弹性豆茎上部署我的应用程序,但它总是失败。我试图在AWS ECR + Fargate和GCP Cloud Run上部署它,它没有任何问题。我还试图将其设置为不可变,但仍然失败。
这是我的Dockerfile

#Stage 1 - Install dependencies and build the app
FROM debian:latest AS build-env

# Install flutter dependencies
RUN apt-get update 
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3
RUN apt-get clean

# Clone the flutter repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter

# Set flutter path
# RUN /usr/local/flutter/bin/flutter doctor -v
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"

# Run flutter doctor
RUN flutter doctor -v
# Enable flutter web
RUN flutter channel master
RUN flutter upgrade
RUN flutter config --enable-web

# Copy files to container and build
RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web

# Stage 2 - Create the run-time image
FROM nginx:1.21.1-alpine
COPY --from=build-env /app/build/web /usr/share/nginx/html

它在第7步左右崩溃。

Step 7/18 : RUN flutter channel stable
 ---> Running in af4a4105e884
[91mDownloading Linux x64 Dart SDK from Flutter engine 4e6cbe0fc22d0a7c3f3380dff23ad2cad84b2170...
[0m  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0  198M    0 28911    0     0   159k      0  0:21:12 --:--:--  0:21:12  158k
 53  198M   53  106M    0     0  92.3M      0  0:00:02  0:00:01  0:00:01 92.2M
100  198M  100  198M    0     0   107M      0  0:00:01  0:00:01 --:--:--  107M
[91mBuilding flutter tool...
[0mResolving dependencies...
Got dependencies.
[91m
===== CRASH =====
si_signo=Bus error(7), si_code=2, si_addr=0x7fafc3d69000
version=3.0.0-300.0.dev (dev) (Sat Mar 4 11:55:16 2023 -0800) on "linux_x64"
pid=212, thread=218, isolate_group=kernel-service(0x7fb004035d10), isolate=kernel-service(0x7fb0040144e0)
os=linux, arch=x64, comp=no, sim=no
isolate_instructions=7fb008b5f000, vm_instructions=556d3f931380
fp=7faff5ffd1c0, sp=7faff5ffd178, pc=7fb010d3f733
  pc 0x00007fb010d3f733 fp 0x00007faff5ffd1c0 /lib/x86_64-linux-gnu/libc.so.6+0x18b733

===== CRASH =====
si_signo=Bus error(7), si_code=2, si_addr=0x7fafc794f040
Aborting reentrant request for stack trace.
[0m[91m/usr/local/flutter/bin/internal/shared.sh: line 178:   212 Aborted                 (core dumped) "$DART" --verbosity=error --disable-dart-dev $FLUTTER_TOOL_ARGS --snapshot="$SNAPSHOT_PATH" --snapshot-kind="app-jit" --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" --no-enable-mirrors "$SCRIPT_PATH" > /dev/null
[0m
2023/03/07 17:39:54.516708 [INFO] Building app-prod
The command '/bin/sh -c flutter channel stable' returned a non-zero code: 134

2023/03/07 17:39:54.577381 [WARN] failed to execute command: docker-compose build, retrying...
2023/03/07 17:39:54.577428 [INFO] Running command /bin/sh -c docker-compose build
2023/03/07 18:00:11.377269 [INFO] Sending build context to Docker daemon  580.1kB Step 1/18 : FROM ubuntu:20.04 AS builder

我的许多应用程序,如React,NodeJS都在Elastic Beanstalk上运行。我希望我的Flutter Web也能在Elastic Beanstalk上运行。

dxxyhpgq

dxxyhpgq1#

Elastic Beanstalk似乎无法正确构建Flutter Web应用程序。但经过几天的实验,我终于能够将Flutter Web应用程序部署到ELB。
我所做的是通过使用Github操作和ECR在部署过程中添加了一个新层。
以下是我的CI/CD流程:

  1. Flutter的Web构建将发生在Github操作上,而不是在弹性beanstalk中构建。
    1.构建完成后,GitHub操作将在AWS ECR上推送构建映像。
    1.在成功推送到ECR之后,我们必须将我们的项目代码以zip格式推送到s3,以便Elastic beanstalk能够拉取包含docker-compose的文件。我们的项目必须包含docker-compose.yml,稍后将由elastic beanstalk执行。
    1.然后GitHub操作将触发弹性beanstalk从s3中提取包含docker-compose.yml文件的zip文件。
    1.弹性beanstalk将自动运行docker-compose.yml,从ECR中提取图像。

DOCKERFILE

首先,请确保您的项目正在运行Flutter Stable 3.7.7或最新的稳定版本,以便我们的Dockerfile不会遇到一些错误。要检查run flutter doctor.,请在我们的根项目中创建一个名为Dockerfile的文件,然后复制并粘贴以下内容:

#Stage 1 - Install dependencies and build the app
FROM debian:latest AS build-env

# Install flutter dependencies
RUN apt-get update 
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3
RUN apt-get clean

# Clone the flutter repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter

# Set flutter path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"

# Enable flutter web
RUN flutter channel stable
RUN flutter upgrade
RUN flutter config --enable-web

# Copy files to container and build
RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web

# Stage 2 - Create the run-time image
FROM nginx:1.21.1-alpine
COPY --from=build-env /app/build/web /usr/share/nginx/html

AWS ECR

转到AWS ECR并为您的映像创建存储库。
1.复制存储库名称,例如:projectrepo1
1.复制URI ex:ACCNUM.dkr.ecr.REGION.amazonaws.com/projectrepo1

DOCKER-COMPOSE.YML

在你的应用程序的根目录下,创建一个docker-compose.yml文件,这将由弹性beanstalk执行。在docker-compose.yml中粘贴以下内容,然后用我们之前复制的URI替换图像。你可以为容器命名任何你想要的名字。

version: "3.8"
services:
  flutterweb:
    image: ACCNUM.dkr.ecr.REGION.amazonaws.com/projectrepo1
    container_name: flutterweb_container1
    ports:
      - '80:80'

弹性豆柱

创建一个新的弹性beanstalk并选择Docker作为平台。
1.复制应用程序名称
1.复制环境名称

用户和用户组

1.转到IAM
1.创建用户组,并添加以下策略AmazonEC2ContainerRegistryFullAccessAmazonS3FullAccessAdministratorAccess-AWSElasticBeanstalkAmazonElasticContainerRegistryPublicFullAccess
1.将新用户和该用户添加到用户组
1.为用户生成ACCESS KEYSECRET KEY,确保复制。

ELASTIC BEANSTALK ECR ACCESS

1.转至IAM角色
1.查找aws-elasticbeanstalk-ec2-role并打开该角色。为该角色添加以下策略AmazonEC2ContainerRegistryFullAccess
这将允许弹性beanstalk访问我们的容器注册表。

去你的Github项目添加一个SECRET

  • AWS访问密钥ID:您的访问密钥
  • AWS机密访问密钥:您的秘密钥匙

GITHUB操作

在我们的根文件夹中,创建一个名为.github的forder,在其中创建另一个名为workflows的文件夹,在工作流中创建一个名为deploy-aws.yml的文件。
在deploy-aws.yml中粘贴以下内容:

name: Deploy Flutter Web To AWS ELB
on:
  push:
    branches:
    - development
jobs:
  build:
    runs-on: ubuntu-latest
    steps:

    - name: Checkout source code
      uses: actions/checkout@v2

    - 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: YOUR_ECR_REGION

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Build, tag, and push image to Amazon ECR
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: YOUR_REPOSITORY_NAME
        IMAGE_TAG: latest
      run: |
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

    - name: Generate deployment package
      run: zip -r deploy.zip . -x '*.git*'

    - name: Deploy to EB
      uses: einaregilsson/beanstalk-deploy@v21
      with:
        aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        application_name: YOUR_ELASTIC_BEANSTALK_APPLICATION_NAME
        environment_name: YOUR_ELASTIC_BEANSTALK_ENVIRONMENT_NAME
        version_label: ${{ github.sha }}
        region: YOUR_ELASTIC_BEANSTALK_REGION
        deployment_package: deploy.zip

确保已更换以下各项:

  • 您的ECR地区:例如:ap-southeast-1
  • 您的存储库名称:例如:projectrepo 1
  • Your_ELASTIC_BEANSTALK_REGION:例如:ap-southeast-1
  • 您的_ELASTIC_BEANSTALK_应用程序_名称:例如:flutterweb
  • 您的弹性豆茎环境名称:例如:flutterweb-env

这个解决方案对我来说很有效。稍后我将使用AWS Codebuild而不是Github操作来添加一种新方法。

相关问题