|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +# Environment variables available to all jobs and steps in this workflow |
| 9 | +env: |
| 10 | + RUN_PROJECT: ${{ secrets.RUN_PROJECT }} |
| 11 | + RUN_REGION: ${{ secrets.RUN_REGION }} |
| 12 | + RUN_SERVICE: ${{ secrets.RUN_SERVICE }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + setup-build-deploy: |
| 16 | + name: Setup, Build, and Deploy |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v1 |
| 22 | + |
| 23 | + - name: Set up JDK 1.8 |
| 24 | + uses: actions/setup-java@v1 |
| 25 | + with: |
| 26 | + java-version: 1.8 |
| 27 | + |
| 28 | + - name: Set COMMIT and LASTMOD |
| 29 | + run: | |
| 30 | + sudo apt-get install -y xmlstarlet |
| 31 | + xmlstarlet edit --inplace --update "//_:web-app/_:context-param/_:param-name[text()='COMMIT']/parent::*/_:param-value" -v ${GITHUB_SHA:0:7} www/WEB-INF/web.xml |
| 32 | + xmlstarlet edit --inplace --update "//_:web-app/_:context-param/_:param-name[text()='LASTMOD']/parent::*/_:param-value" -v "$(date -u +%Y-%m-%dT%H:%M:%SZ)" www/WEB-INF/web.xml |
| 33 | +
|
| 34 | + # Setup gcloud CLI |
| 35 | + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master |
| 36 | + with: |
| 37 | + version: '275.0.0' |
| 38 | + service_account_email: ${{ secrets.GCP_SA_EMAIL }} |
| 39 | + service_account_key: ${{ secrets.GCP_SA_KEY }} |
| 40 | + |
| 41 | + # Configure gcloud CLI |
| 42 | + - name: gcloud Set up |
| 43 | + run: | |
| 44 | + gcloud config set project $RUN_PROJECT |
| 45 | +
|
| 46 | + # Build and push image to Google Container Registry |
| 47 | + - name: Docker Build |
| 48 | + run: | |
| 49 | + docker build -t gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA . |
| 50 | +
|
| 51 | + - name: GCloud auth to docker |
| 52 | + run: | |
| 53 | + gcloud auth configure-docker |
| 54 | +
|
| 55 | + - name: Push to registry |
| 56 | + run: | |
| 57 | + docker push gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA |
| 58 | +
|
| 59 | + # Deploy image to Cloud Run |
| 60 | + - name: Deploy |
| 61 | + run: | |
| 62 | + gcloud run deploy $RUN_SERVICE \ |
| 63 | + --allow-unauthenticated \ |
| 64 | + --image gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA \ |
| 65 | + --platform managed \ |
| 66 | + --project ${RUN_PROJECT} \ |
| 67 | + --region $RUN_REGION |
0 commit comments