Build and Push Datashare Image #14
Workflow file for this run
This file contains 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@v2 | |
with: | |
repository: 'neoreuters/tr-datashare-client' | |
ref: 'master' | |
- name: Setup Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: npm install | |
- name: Build frontend for distribution | |
run: npm run build | |
- name: Upload frontend distribution | |
uses: actions/upload-artifact@v2 | |
with: | |
name: frontend-distribution | |
path: dist | |
build-backend: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_DB: datashare | |
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@v2 | |
with: | |
fetch-depth: 0 | |
- name: Extract version from pom.xml | |
id: get_version | |
run: | | |
VERSION=$(cat pom.xml | grep '<version>[0-9.]\+' | sed 's/<version>\([0-9.]\+\)<\/version>/\1/g' | tr -d '[:space:]') | |
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 -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 -a -f ./datashare-db/scr/init.sql | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '11' | |
distribution: 'adopt' | |
- name: Set up Maven | |
uses: stCarolas/setup-maven@v4 | |
with: | |
maven-version: 3.6.3 | |
- name: Validate project | |
run: mvn validate | |
- name: Install commons-test | |
run: mvn -pl commons-test -am install | |
- 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@v2 | |
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 |