OK-735: Testataan uin github deploymenttia #54
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: Ovara build workflow | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- '**.md' | |
jobs: | |
# BACKEND | |
build-backend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/cache@v4 | |
id: restore-build | |
with: | |
path: | | |
ovara-backend/target | |
key: ${{ github.sha }} | |
- name: Cache local Maven repository | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
cache: 'maven' | |
- uses: szenius/set-timezone@v1.0 | |
with: | |
timezoneLinux: "Europe/Helsinki" | |
- name: Build with Maven | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
cd ovara-backend | |
mvn clean package -B -DskipTests | |
deploy-backend-container: | |
needs: build-backend | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/cache@v4 | |
id: restore-build | |
with: | |
path: | | |
ovara-backend/target | |
key: ${{ github.sha }} | |
- name: Build and deploy Docker container | |
shell: bash | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
run: | | |
set -euo pipefail | |
git clone https://github.com/Opetushallitus/ci-tools.git | |
source ci-tools/common/setup-tools.sh | |
export ARTIFACT_NAME="ovara-backend" | |
export BASE_IMAGE="baseimage-fatjar-openjdk21:master" | |
source ci-tools/common/setup-tools.sh | |
mv ovara-backend/target/ovara-backend-*.jar $DOCKER_BUILD_DIR/artifact/${ARTIFACT_NAME}.jar | |
cp -vr ovara-backend/src/main/resources/oph-configuration $DOCKER_BUILD_DIR/config/oph-configuration/ | |
./ci-tools/common/pull-image.sh | |
./ci-tools/github-build/build-fatjar.sh $ARTIFACT_NAME | |
./ci-tools/github-build/upload-image.sh $ARTIFACT_NAME | |
# UI | |
lint: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run lint | |
run: | | |
npm run typecheck | |
npm run lint | |
test: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run unit tests | |
run: npm test | |
deploy-ui-zip: | |
needs: [lint, test] | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci --no-audit --prefer-offline | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_OPH_UTILITY_ROLE_ARN }} | |
role-session-name: ovara-ui-deploy-zip | |
aws-region: eu-west-1 | |
- name: Deploy zip to s3 | |
env: | |
bucket: ${{ secrets.BUCKET_NAME }} | |
run: | | |
npm run build | |
zip -r ga-${{github.run_number}}.zip .next/*.* .next/BUILD_ID .next/static .next/standalone public | |
aws s3 cp --no-progress ga-${{github.run_number}}.zip s3://"$bucket"/ga-${{github.run_number}}.zip |