diff --git a/.github/workflows/tests-backend-build-oci-images.yml b/.github/workflows/tests-backend-build-oci-images.yml new file mode 100644 index 0000000000..92b70d91ad --- /dev/null +++ b/.github/workflows/tests-backend-build-oci-images.yml @@ -0,0 +1,248 @@ +name: Build and publish container images for test jobs to GitHub Container Registry + +on: + push: + branches: + - 'main' + - 'develop' + - 'staging' + - 'production' + paths: + - 'api/**' + - 'postgresql/**' + - 'webshot/**' + - '.github/**' + pull_request: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + +jobs: + + build_and_push_api: + name: Build and push API service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-api + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -f api.Dockerfile + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./api + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + build_and_push_geoprocesing: + name: Build and push Geoprocessing service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-geoprocessing + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -f geo.Dockerfile + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./api + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + build_and_push_apidb: + name: Build and push apidb service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-postgresql-api + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -f apidb.Dockerfile + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./postgresql + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + build_and_push_geodb: + name: Build and push geodb service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-postgresql-geo-api + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -f geodb.Dockerfile + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./postgresql + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + build_and_push_redis: + name: Build and push Redis service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-redis + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./redis + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + + build_and_push_webshot: + name: Build and push Webshot service container image to registry + runs-on: ubuntu-22.04 + timeout-minutes: 30 + env: + REPOSITORY: marxan-webshot + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch ids + shell: bash + run: | + echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT + echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Build container image + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker build \ + -t $REGISTRY/$REPOSITORY:$IMAGE_TAG ./webshot + + - name: Push container image to registry + env: + IMAGE_TAG: ${{ steps.extract_branch.outputs.shortsha }} + run: | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG