From 76ff11217f6549003cba057a0260aa25ef3251b9 Mon Sep 17 00:00:00 2001 From: leoguillaume Date: Thu, 11 Jul 2024 09:08:17 +0200 Subject: [PATCH] chore: add ci/cd to build --- .github/workflows/build.yml | 37 +++++++++++++++++++++++++++++++++++++ compose.yml | 4 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..ca11164d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build docker image when pushing on main branch + +on: + push: + branches: + - main + - dev + +jobs: + build-fastapi: + environment: ${{ github.ref_name == 'dev' || github.ref_name == 'main' }} + name: Build and push from ${{ github.ref_name }}/${{ github.sha }} + runs-on: ubuntu-latest + env: + IMAGE_NAME: ghcr.io/${{ github.repository }}/fastapi + IMAGE_TAG: ${{ github.sha }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: app + push: true + tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + #,${{ env.IMAGE_NAME }}:${{ github.ref_name == 'dev' && 'latest' || github.ref_name == 'main' && 'stable' }} diff --git a/compose.yml b/compose.yml index c7a2438f..9ccbf583 100644 --- a/compose.yml +++ b/compose.yml @@ -1,8 +1,8 @@ version: "3.8" services: - api: - image: albert/api:latest + fastapi: + image: ghcr.io/etalab-ia/albert-api/fastapi:latest command: uvicorn app.main:app --host 0.0.0.0 --port 8000 build: context: ./app