Update tray libraries #75
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 Docker to GCloud | |
on: | |
push: | |
branches: | |
- master | |
- docker | |
jobs: | |
deploy: | |
name: Deploy using GCloud | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.ORG_TOKEN }} | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 11 | |
- name: Prepare environment secrets | |
run: | | |
printf "${{ secrets.GCP_SA_KEY }}" > backend/src/main/resources/sa.json | |
- name: Auth GCloud | |
id: auth | |
uses: 'google-github-actions/auth@v1' | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
credentials_json: '${{ secrets.GCP_SA_KEY }}' | |
- name: Setup GCloud | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Assembly | |
run: | | |
printf "realm=github\nhost=www.github.com\nuser=${{ vars.ORG_USERNAME }}\password=${{ secrets.ORG_TOKEN }}" > ~/gihub.credentials | |
printf "[github]\n actor=${{ vars.ORG_USERNAME }}\n token=${{ secrets.ORG_TOKEN }}" > ~/.gitconfig | |
sbt backend/Docker/publishLocal | |
- name: Deploy to GCloud | |
env: | |
BRANCH_NAME: ${{ github.ref_name }} | |
IMAGE: europe-west1-docker.pkg.dev/loctio/loctio/loctio | |
SERVICE: loctio | |
run: | | |
gcloud auth configure-docker europe-west1-docker.pkg.dev | |
gcloud config set core/project loctio | |
gcloud config set run/region europe-west1 | |
docker tag ${SERVICE}:0.7.0 ${IMAGE}:${BRANCH_NAME} | |
docker push ${IMAGE}:${BRANCH_NAME} | |
gcloud run deploy ${SERVICE} --image ${IMAGE}:${BRANCH_NAME} | |
gcloud run services update-traffic ${SERVICE} --to-latest | |
# List images with no tags | |
gcloud container images list-tags ${IMAGE} --filter='-tags:*' --format="get(digest)" --limit=10 > tags | |
# Delete the images | |
while read p; do gcloud container images delete "${IMAGE}@$p" --quiet; done < tags | |
# List all revisions | |
gcloud run revisions list --service ${SERVICE} | |
# List last created revision (it should be the active one) | |
ACTIVE=$(gcloud run services describe ${SERVICE} --format="value(status.latestCreatedRevisionName)" --region=europe-west1) | |
if [ "$ACTIVE" != "" ]; then | |
gcloud run revisions list --service ${SERVICE} --filter="metadata.name!=$ACTIVE" --format="get(metadata.name)" >nonactive | |
echo "Delete all but $ACTIVE" | |
while read p; do gcloud run revisions delete $p --quiet; done < nonactive | |
fi |