From b3bec88ac01fda6f5882691cff7d7fdcde2ba4c8 Mon Sep 17 00:00:00 2001 From: Yosef Bedaso Date: Wed, 27 Mar 2024 10:21:36 -0700 Subject: [PATCH 1/2] ci: add workflow for ecs deployment --- .dockerignore | 5 +++ .github/workflows/publish.yaml | 58 ++++++++++++++++++++++++++++++++++ Dockerfile | 20 ++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/publish.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..27d8913 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/.git +/.github +/.gitignore +/.venv +/venv \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..6b70eef --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,58 @@ +name: Tag and Publish +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Pull latest changes + run: git pull origin main + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Github Packages + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v3 + with: + # relative path to the place where source code with Dockerfile is located + context: . + push: true + tags: ghcr.io/allenneuraldynamics/foraging-behavior-browser:latest + update_ecs_service : + runs-on: ubuntu-latest + needs: publish + permissions: + id-token: write + contents: read + env: + ECS_ROLE: ${{ secrets.AWS_FORAGING_ECS_ROLE }} + AWS_REGION : ${{ vars.AWS_REGION_DEV }} + ECS_CLUSTER : ${{ vars.AWS_FORAGING_ECS_CLUSTER }} + ECS_SERVICE : ${{ vars.AWS_FORAGING_ECS_SERVICE }} + steps: + - uses: actions/checkout@master + - name: Pull latest changes + run: git pull origin main + - name: Set up Python 3.8 + uses: actions/setup-python@v3 + with: + python-version: 3.8 + - name: Configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ env.ECS_ROLE }} + role-session-name: github-ecs-update-service + aws-region: ${{ env.AWS_REGION }} + - name: Update ECS service + run: | + python -m pip install awscli + aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1251079 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.8-slim + +WORKDIR /app + +COPY . . + +RUN apt-get update && apt-get install -y \ + build-essential \ + curl \ + git \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +RUN pip3 install -r requirements.txt --no-cache-dir + +EXPOSE 8501 + +HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health + +ENTRYPOINT ["streamlit", "run", "code/Home.py", "--server.port=8501", "--server.address=0.0.0.0"] From add6b4c3bbdda342145d9c844ad25b4605ab3ac7 Mon Sep 17 00:00:00 2001 From: Yosef Bedaso Date: Wed, 27 Mar 2024 15:06:31 -0700 Subject: [PATCH 2/2] ci: add eof new line --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 27d8913..0f6d436 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,4 @@ /.github /.gitignore /.venv -/venv \ No newline at end of file +/venv