Deploy and run calculate #87
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: "Deploy and run calculate" | |
on: | |
# This job is triggered only manually (in practice via a github API rest call | |
# by the otp application) if needed. | |
# we have to register on push to make the event show up, but it does not actually do anything on push (note "if" conditions below in job) | |
push: | |
workflow_dispatch: | |
env: | |
PROJECT_NAME: "odh-mentor-otp" | |
API_HOST: http://localhost | |
API_PATH: /otp/routers/openmove | |
API_PORT: 8080 | |
DOCKER_IMAGE_OTP: ghcr.io/${{ github.repository }}/odh-mentor-otp-calculate | |
DOCKER_TAG: ${{ github.sha }} | |
jobs: | |
run-calculate-test: | |
runs-on: ubuntu-20.04 | |
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' | |
concurrency: build-calc-test | |
steps: | |
- name: Spin up EC2 instance | |
run: | | |
aws ec2 start-instances --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
# this used to be a wait (120 sec) to have the efs volume be mounted. If this makes problems, return to a wait 120 | |
- name: Wait for instance to start up | |
run: | | |
aws ec2 wait instance-running --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
- name: Checkout source code | |
uses: noi-techpark/github-actions/checkout@v2 | |
- name: Create .env file | |
uses: noi-techpark/github-actions/env-file@v2 | |
env: | |
X_COMPOSE_PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
X_DOCKER_IMAGE_OTP: ${{ env.DOCKER_IMAGE_OTP }} | |
X_DOCKER_TAG: ${{ env.DOCKER_TAG }} | |
X_EFS_FOLDER: "/opt/odh-mentor-otp-test/" | |
X_GBFS_HOST : "https://gbfs.otp.opendatahub.testingmachine.eu/" | |
X_JAVA_MX: "16G" | |
X_BUILD_GRAPH: "True" | |
X_DOWNLOAD_DATA: "False" | |
X_BACKUP_GRAPH: "True" | |
X_CARSHARING_HOST: "https://carsharing.otp.opendatahub.testingmachine.eu" | |
X_PARKING_HOST: "https://parking.otp.opendatahub.testingmachine.eu" | |
X_DRT_HOST: "https://drt.otp.opendatahub.testingmachine.eu" | |
X_CHARGER_HOST: "https://charger.otp.opendatahub.testingmachine.eu" | |
X_UPDATERS: "True" | |
X_GTFS_FILE: "latestGTFS.zip" | |
X_OTP_OFFICIAL: "False" | |
X_GBFS_VERSION: 1 | |
X_GTFS_RT_URL: "https://efa.sta.bz.it/gtfs-r/" | |
X_GTFS_FEED_ID: 1 | |
X_GEOCODER_BASEURL: "https://geocoder.otp.opendatahub.testingmachine.eu" | |
X_PARKING_BASEURL: "https://parking.otp.opendatahub.testingmachine.eu" | |
X_DRT_BASEURL: "https://drt.otp.opendatahub.testingmachine.eu" | |
X_CHARGER_BASEURL: "https://charger.otp.opendatahub.testingmachine.eu" | |
X_TRAFFIC_BASEURL: "https://traffic.otp.opendatahub.testingmachine.eu" | |
- name: Deploy / run calculation | |
uses: noi-techpark/github-actions/docker-deploy@v2 | |
with: | |
hosts: 'calculate-test' | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
docker-username: 'noi-techpark-bot' | |
docker-password: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
project-name: ${{ env.PROJECT_NAME }} | |
playbook-file: deploy.calculate.test.yml | |
- name: Spin down EC2 instance | |
run: | | |
aws ec2 stop-instances --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
run-calculate-prod: | |
runs-on: ubuntu-20.04 | |
if: github.ref == 'refs/heads/prod' && github.event_name == 'workflow_dispatch' | |
concurrency: build-calc-prod | |
steps: | |
- name: Spin up EC2 instance | |
run: | | |
aws ec2 start-instances --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
# this used to be a wait (120 sec) to have the efs volume be mounted. If this makes problems, return to a wait 120 | |
- name: Wait for instance to start up | |
run: | | |
aws ec2 wait instance-running --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
- name: Checkout source code | |
uses: noi-techpark/github-actions/checkout@v2 | |
- name: Create .env file | |
uses: noi-techpark/github-actions/env-file@v2 | |
env: | |
X_COMPOSE_PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
X_DOCKER_IMAGE_OTP: ${{ env.DOCKER_IMAGE_OTP }} | |
X_DOCKER_TAG: ${{ env.DOCKER_TAG }} | |
X_EFS_FOLDER: "/opt/odh-mentor-otp-prod/" | |
X_GBFS_HOST : "https://gbfs.otp.opendatahub.com/" | |
X_JAVA_MX: "16G" | |
X_BUILD_GRAPH: "True" | |
X_DOWNLOAD_DATA: "False" | |
X_BACKUP_GRAPH: "True" | |
X_CARSHARING_HOST: "https://carsharing.otp.opendatahub.com" | |
X_PARKING_HOST: "https://parking.otp.opendatahub.com" | |
X_DRT_HOST: "https://drt.otp.opendatahub.com" | |
X_CHARGER_HOST: "https://charger.otp.opendatahub.com" | |
X_UPDATERS: "True" | |
X_GTFS_FILE: "latestGTFS.zip" | |
X_OTP_OFFICIAL: "False" | |
X_GBFS_VERSION: 1 | |
X_GTFS_RT_URL: "https://efa.sta.bz.it/gtfs-r/" | |
X_GTFS_FEED_ID: 1 | |
X_GEOCODER_BASEURL: "https://geocoder.otp.opendatahub.com" | |
X_PARKING_BASEURL: "https://parking.otp.opendatahub.com" | |
X_DRT_BASEURL: "https://drt.otp.opendatahub.com" | |
X_CHARGER_BASEURL: "https://charger.otp.opendatahub.com" | |
X_TRAFFIC_BASEURL: "https://traffic.otp.opendatahub.com" | |
- name: Deploy / run calculation | |
uses: noi-techpark/github-actions/docker-deploy@v2 | |
with: | |
hosts: 'calculate-prod' | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
docker-username: 'noi-techpark-bot' | |
docker-password: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
project-name: ${{ env.PROJECT_NAME }} | |
playbook-file: deploy.calculate.prod.yml | |
- name: Spin down EC2 instance | |
if: always() | |
run: | | |
aws ec2 stop-instances --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |