diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml new file mode 100644 index 0000000..097e846 --- /dev/null +++ b/.github/workflows/build-and-publish.yaml @@ -0,0 +1,53 @@ +name: Build and Publish Image +on: [push] + +jobs: + build: + name: Build and publish image + runs-on: ubuntu-22.04 + + 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 + + - name: Build code + id: build-code + run: + ./build.sh --skip-image-build expenses_server_fastapi expenses_react + + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y%m%d%H%M%S')" + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: expenses + tags: latest ${{ github.sha }} ${{ steps.date.outputs.date }} + containerfiles: | + ./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/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 }