diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml new file mode 100644 index 0000000..7ce0449 --- /dev/null +++ b/.github/workflows/build-and-publish.yaml @@ -0,0 +1,71 @@ +name: Build and Publish Image +on: + push: {} + repository_dispatch: + types: [fe-change, be-change] + +jobs: + build: + name: Build and publish image + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + repository: farting-lizards/expenses_server_fastapi + path: expenses_server_fastapi + + - uses: actions/checkout@v4 + with: + repository: farting-lizards/expenses-react + path: expenses-react + + # this the last so we end up inside the cloned directory + - uses: actions/checkout@v4 + with: + path: expenses-container + + - uses: actions/setup-node@v4 + with: + node-version: 16 + + - name: Build code + id: build-code + env: + DISABLE_ESLINT_PLUGIN: "true" + run: | + cd expenses-container \ + && bash -x ./build.sh --skip-image-build ../expenses-react ../expenses_server_fastapi + + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y%m%d%H%M%S')" + + # for arm image building + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: expenses + context: expenses-container + platforms: linux/arm64/v8 + tags: latest ${{ github.sha }} ${{ steps.date.outputs.date }} + containerfiles: | + ./expenses-container/Dockerfile.prod + + - name: Push To quay.io + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: quay.io/farting_lizards + username: ${{ secrets.QUAY_USER }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Print image url + run: | + echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" diff --git a/Dockerfile.prod b/Dockerfile.prod index f09fbc6..71446a6 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -11,7 +11,7 @@ WORKDIR /app COPY src/pyproject.toml src/poetry.lock ./ -RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root +RUN poetry install --without dev --no-root FROM docker.io/arm64v8/python:3-slim as runtime diff --git a/build.sh b/build.sh index 476c641..e49a1f8 100755 --- a/build.sh +++ b/build.sh @@ -19,6 +19,9 @@ function help() { If specified, will only build the container, but not copy any code or files from the frontend or the backend + --skip-image-build + If specified, it will not build the container image (usually for CI) + Arguments: PATH_TO_FRONTEND_REPO Path to the directory containing the frontend code. @@ -37,6 +40,7 @@ EOH function main() { local do_build=true + local do_image_build=true if [[ $# -lt 3 ]]; then echo "Not enough arguments passed" help @@ -54,6 +58,10 @@ function main() { do_build=false shift fi + if [[ "$1" == "--skip-image-build" ]]; then + do_image_build=false + shift + fi local fe_path="${1:?No frontend path passed}" local be_path="${2:?No backend path passed}" local env="${3:-}" @@ -75,7 +83,9 @@ function main() { copyFrontend "$fe_path" "src/static" fi - buildContainer "$arch" "$dockerfile" + if $do_image_build; then + buildContainer "$arch" "$dockerfile" + fi }