Create build_and_push.yaml #12
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Datashare Image | |
| on: | |
| push: | |
| tags: | |
| - '*.*.*' | |
| env: | |
| MAVEN_OPTS: "-Xms512m -Xmx512m -Xss10M" | |
| jobs: | |
| build-frontend: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| frontend-artifacts-path: ${{ steps.build_artifacts.outputs.distribution-path }} | |
| steps: | |
| - name: Checkout frontend repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: 'icij/datashare-client' | |
| ref: 'main' | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm install --legacy-peer-deps | |
| - name: Build frontend for distribution | |
| run: npm run build | |
| - name: Upload frontend distribution | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-distribution | |
| path: dist | |
| build-backend: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:latest | |
| env: | |
| POSTGRES_DB: datashare_liquibase | |
| POSTGRES_USER: dstest | |
| POSTGRES_PASSWORD: test | |
| ports: | |
| - 5432:5432 | |
| elasticsearch: | |
| image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3 | |
| env: | |
| discovery.type: "single-node" | |
| discovery.seed_hosts: "elasticsearch:9200" | |
| ES_JAVA_OPTS: "-Xmx256m -Xms256m" | |
| ports: | |
| - 9200:9200 | |
| - 9300:9300 | |
| redis: | |
| image: redis:latest | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from pom.xml | |
| id: get_version | |
| run: | | |
| VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
| echo "::set-output name=VERSION::$VERSION" | |
| - name: Print version | |
| run: echo "The version is ${{ steps.get_version.outputs.VERSION }}" | |
| - name: Wait for PostgreSQL to be ready | |
| run: | | |
| until PGPASSWORD=test psql -h localhost -U dstest -d datashare_liquibase -c '\q'; do | |
| >&2 echo "Postgres is still unavailable - sleeping" | |
| sleep 1 | |
| done | |
| >&2 echo "Postgres is up - executing command" | |
| - name: Run init script on PostgreSQL | |
| run: PGPASSWORD=test psql -h localhost -U dstest -d datashare_liquibase -a -f ./datashare-db/scr/init.sql | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'adopt' | |
| - name: Set up Maven | |
| uses: stCarolas/setup-maven@v4 | |
| with: | |
| maven-version: 3.6.3 | |
| - name: Import GPG key | |
| uses: crazy-max/ghaction-import-gpg@v6 | |
| with: | |
| gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
| - name: Validate project | |
| run: mvn validate | |
| - name: Install commons-test | |
| run: mvn -pl commons-test -am install -DskipTests | |
| - name: Update database | |
| run: mvn -pl datashare-db liquibase:update | |
| - name: Build datashare-app and datashare-nlp-corenlp | |
| run: mvn -pl datashare-app,datashare-nlp-corenlp -am install -Dmaven.test.skip=true -Dgpg.skip=true | |
| - name: Download frontend artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frontend-distribution | |
| path: app | |
| - name: Package everything | |
| run: mvn -pl datashare-dist package | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_REPO=${GITHUB_REPOSITORY@L}" >> ${GITHUB_ENV} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./datashare-dist/target/datashare-dist-${{ steps.get_version.outputs.VERSION }}-docker | |
| file: ./datashare-dist/target/datashare-dist-${{ steps.get_version.outputs.VERSION }}-docker/Dockerfile | |
| push: true | |
| tags: ghcr.io/${{ env.IMAGE_REPO }}:${{ github.ref_name }} | |
| platforms: linux/amd64,linux/arm64 |