Update version id per commit id. #51
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-review | |
on: | |
push: | |
branches: | |
- main | |
env: | |
IMAGE_NAME: collision-mapper | |
DOCKER_USERNAME: flyingmonkeys1996 | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER }} # Database username | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} # Database password | |
POSTGRES_DB: collisions # Database name | |
jobs: | |
run-tests: | |
runs-on: ubuntu-latest | |
# Docker Hub image that `container-job` executes in | |
container: node:20-bookworm-slim | |
# Service containers to run with `container-job` | |
services: | |
# Label used to access the service container | |
postgres: | |
# Docker Hub image | |
image: postgis/postgis:latest # Use the latest postgis image | |
# Set health checks to wait until postgres has started | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
# Maps tcp port 5432 on service container to the host | |
- 5432:5432 | |
env: | |
POSTGRES_USER: ${{ env.POSTGRES_USER }} | |
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} | |
POSTGRES_DB: ${{ env.POSTGRES_DB }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 21 | |
cache: 'gradle' | |
- name: Set up PostgreSQL client tools | |
run: apt-get update && apt-get install -y postgresql-client | |
- name: Migrate database | |
run: | | |
# Populate real database | |
psql -h postgres -U $POSTGRES_USER -d $POSTGRES_DB -f ./databases/init-scripts/migration.sql | |
# Create test database | |
TEST_DATABASE="${POSTGRES_DB}_test" | |
psql -h postgres -U $POSTGRES_USER -d $POSTGRES_DB -c "create database $TEST_DATABASE" | |
psql -h postgres -U $POSTGRES_USER -d $TEST_DATABASE -f ./databases/init-scripts/migration.sql | |
# Verify the tables were created | |
psql -h postgres -U $POSTGRES_USER -d $POSTGRES_DB -c "\dt data" | |
psql -h postgres -U $POSTGRES_USER -d $POSTGRES_DB -c "\dt cluster" | |
env: | |
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }} | |
- name: "build" | |
run: ./gradlew build | |
env: | |
DATABASE_HOST: postgres | |
DATABASE_PORT: 5432 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: basic-server.jar | |
path: applications/basic-server/build/libs/basic-server.jar | |
retention-days: 1 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: data-analyzer-server.jar | |
path: applications/data-analyzer-server/build/libs/data-analyzer-server.jar | |
retention-days: 1 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: data-collector-server.jar | |
path: applications/data-collector-server/build/libs/data-collector-server.jar | |
retention-days: 1 | |
artifact-registry: | |
runs-on: ubuntu-latest | |
needs: [run-tests] | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: basic-server.jar | |
path: applications/basic-server/build/libs | |
- uses: actions/download-artifact@v4 | |
with: | |
name: data-analyzer-server.jar | |
path: applications/data-analyzer-server/build/libs | |
- uses: actions/download-artifact@v4 | |
with: | |
name: data-collector-server.jar | |
path: applications/data-collector-server/build/libs | |
- name: Build Docker image | |
run: docker build . --file Dockerfile --tag image | |
- name: Push Docker image | |
run: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u $DOCKER_USERNAME --password-stdin | |
IMAGE_ID=$DOCKER_USERNAME/$IMAGE_NAME | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
# Use the commit SHA for a unique image tag | |
IMAGE_TAG=${{ github.sha }} | |
# You can also limit the tag length if needed | |
SHORT_IMAGE_TAG=$(echo "$IMAGE_TAG" | cut -c1-8) # Use the first 8 characters | |
docker tag image $IMAGE_ID:$SHORT_IMAGE_TAG | |
docker push $IMAGE_ID:$SHORT_IMAGE_TAG | |
basic-server-review: | |
runs-on: ubuntu-latest | |
needs: [artifact-registry] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/[email protected] | |
with: | |
credentials_json: ${{ secrets.GOOGLE_KEY }} | |
- uses: google-github-actions/setup-gcloud@v2 | |
- name: 'Deploy' | |
id: 'deploy' | |
run: |- | |
IMAGE_TAG=${{ github.sha }} | |
gcloud components install beta --quiet | |
gcloud run deploy basic-server \ | |
--image=docker.io/flyingmonkeys1996/collision-mapper:$IMAGE_TAG \ | |
--allow-unauthenticated \ | |
--port=8080 \ | |
--service-account=320300059816-compute@developer.gserviceaccount.com \ | |
--set-env-vars='APP=opt/applications/basic-server.jar,POSTGRES_USER=${{ env.POSTGRES_USER }},POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }},USE_SSL=true' \ | |
--region=us-central1 \ | |
--project=collision-mappter \ | |
--vpc-connector=projects/collision-mappter/locations/us-central1/connectors/collision-mapper \ | |
--add-cloudsql-instances=collision-mappter:us-central1:collision-mapper-db | |
gcloud beta run services add-iam-policy-binding basic-server \ | |
--region=us-central1 \ | |
--member=allUsers \ | |
--role=roles/run.invoker \ | |
--project=collision-mappter | |
deploy-data-analyzer-review: | |
runs-on: ubuntu-latest | |
needs: [artifact-registry] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/[email protected] | |
with: | |
credentials_json: ${{ secrets.GOOGLE_KEY }} | |
- uses: google-github-actions/setup-gcloud@v2 | |
- id: 'gcloud' | |
name: 'gcloud' | |
run: |- | |
IMAGE_TAG=${{ github.sha }} | |
gcloud components install beta --quiet | |
gcloud run deploy data-analyzer \ | |
--image=docker.io/flyingmonkeys1996/collision-mapper:$IMAGE_TAG \ | |
--allow-unauthenticated \ | |
--port=8080 \ | |
--service-account=320300059816-compute@developer.gserviceaccount.com \ | |
--set-env-vars='APP=opt/applications/data-analyzer-server.jar,POSTGRES_USER=${{ env.POSTGRES_USER }},POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }},USE_SSL=true,COLLECTOR_URL=https://data-collector-320300059816.us-central1.run.app' \ | |
--region=us-central1 \ | |
--project=collision-mappter \ | |
--vpc-connector=projects/collision-mappter/locations/us-central1/connectors/collision-mapper \ | |
--add-cloudsql-instances=collision-mappter:us-central1:collision-mapper-db | |
gcloud beta run services add-iam-policy-binding data-analyzer \ | |
--region=us-central1 \ | |
--member=allUsers \ | |
--role=roles/run.invoker \ | |
--project=collision-mappter | |
data-collector-review: | |
runs-on: ubuntu-latest | |
needs: [artifact-registry] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/[email protected] | |
with: | |
credentials_json: ${{ secrets.GOOGLE_KEY }} | |
- uses: google-github-actions/setup-gcloud@v2 | |
- id: 'gcloud' | |
name: 'gcloud' | |
run: |- | |
IMAGE_TAG=${{ github.sha }} | |
gcloud components install beta --quiet | |
gcloud run deploy data-collector \ | |
--image=docker.io/flyingmonkeys1996/collision-mapper:$IMAGE_TAG \ | |
--allow-unauthenticated \ | |
--port=8080 \ | |
--service-account=320300059816-compute@developer.gserviceaccount.com \ | |
--set-env-vars='APP=opt/applications/data-collector-server.jar,POSTGRES_USER=${{ env.POSTGRES_USER }},POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }},USE_SSL=true' \ | |
--region=us-central1 \ | |
--project=collision-mappter \ | |
--vpc-connector=projects/collision-mappter/locations/us-central1/connectors/collision-mapper \ | |
--add-cloudsql-instances=collision-mappter:us-central1:collision-mapper-db | |
gcloud beta run services add-iam-policy-binding data-collector \ | |
--region=us-central1 \ | |
--member=allUsers \ | |
--role=roles/run.invoker \ | |
--project=collision-mappter |