add init script? hope it works. #39
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 | |
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 | |
# Provide the password for postgres | |
env: | |
POSTGRES_USER: postgres # Database username | |
POSTGRES_PASSWORD: password # Database password | |
POSTGRES_DB: collisions # Database name | |
volumes: | |
# Move the needed scripts into the docker initialization directory to be executed on the first boot. | |
- ./databases/init-scripts:/docker-entrypoint-initdb.d | |
# 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 | |
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: Verify Table Creation | |
run: | | |
# Query to check if the table exists | |
psql -h postgres -U postgres -d collisions -c "\dt data" | |
psql -h postgres -U postgres -d collisions -c "\dt cluster" | |
env: | |
PGPASSWORD: password # Database password | |
- name: "build" | |
run: ./gradlew build | |
env: | |
DATABASE_HOST: postgres | |
DATABASE_PORT: 5432 | |
- name: Cleanup | |
run: | | |
# Cleanup the named volume for PostgreSQL data | |
docker volume rm postgres-data || echo "Volume 'postgres-data' not found, skipping cleanup." | |
# Optionally, remove any local initialization scripts if needed | |
rm -rf ./databases/init-scripts/* || echo "No init scripts to remove." | |
- 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 | |
docker tag image $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
# 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: |- | |
# gcloud components install beta --quiet | |
# gcloud run deploy basic-server \ | |
# --image=docker.io/flyingmonkeys1996/collision-mapper:latest \ | |
# --allow-unauthenticated \ | |
# --port=8080 \ | |
# --service-account=320300059816-compute@developer.gserviceaccount.com \ | |
# --set-env-vars='APP=opt/applications/basic-server.jar' \ | |
# --region=us-central1 \ | |
# --project=collision-mappter | |
# 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: |- | |
# gcloud components install beta --quiet | |
# gcloud run deploy data-analyzer \ | |
# --image=docker.io/flyingmonkeys1996/collision-mapper:latest \ | |
# --allow-unauthenticated \ | |
# --port=8080 \ | |
# --service-account=320300059816-compute@developer.gserviceaccount.com \ | |
# --set-env-vars='APP=opt/applications/data-analyzer-server.jar' \ | |
# --region=us-central1 \ | |
# --project=collision-mappter | |
# 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: |- | |
# gcloud components install beta --quiet | |
# gcloud run deploy data-collector \ | |
# --image=docker.io/flyingmonkeys1996/collision-mapper:latest \ | |
# --allow-unauthenticated \ | |
# --port=8080 \ | |
# --service-account=320300059816-compute@developer.gserviceaccount.com \ | |
# --set-env-vars='APP=opt/applications/data-collector-server.jar' \ | |
# --region=us-central1 \ | |
# --project=collision-mappter | |
# gcloud beta run services add-iam-policy-binding data-collector \ | |
# --region=us-central1 \ | |
# --member=allUsers \ | |
# --role=roles/run.invoker \ | |
# --project=collision-mappter |