webapp #894
Workflow file for this run
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: webapp | |
on: | |
push: | |
branches: | |
- "main" | |
create: | |
tags: | |
- "*" | |
# workflow_dispatch: | |
# branches: | |
# - "*" | |
# tags: | |
# - "*" | |
jobs: | |
check_env: | |
runs-on: ubuntu-latest | |
container: alpine:latest | |
steps: | |
- id: ref_check | |
run: | | |
echo "Running on branch ${{ github.ref }}" | |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then | |
echo "::set-output name=env_name::staging" | |
elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then | |
echo "::set-output name=env_name::preview" | |
else | |
echo "::set-output name=env_name::development" | |
fi | |
outputs: | |
env_name: ${{ steps.ref_check.outputs.env_name }} | |
build: | |
needs: [check_env] | |
container: | |
image: node:16-slim | |
runs-on: ubuntu-latest | |
environment: ${{ needs.check_env.outputs.env_name }} | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v3 | |
- name: setup env | |
shell: bash | |
run: | | |
sed -i "s%eas.build.development.env%eas.build.${{ needs.check_env.outputs.env_name }}.env%" app.config.js | |
- name: Setup Nodejs with yarn caching | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "16" | |
cache: yarn | |
- name: Setup Expo | |
run: | | |
yarn global add [email protected] | |
- name: Build | |
run: | | |
yarn install | |
expo build:web | |
- name: Archive build | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-${{ needs.check_env.outputs.env_name }} | |
path: web-build | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v2 | |
# # Setup gcloud CLI | |
# - name: "auth google" | |
# uses: "google-github-actions/auth@v0" | |
# with: | |
# credentials_json: "${{ secrets.GKE_SA_KEY }}" | |
# - name: "Set up Cloud SDK" | |
# uses: "google-github-actions/setup-gcloud@v0" | |
# - name: "configure docker" | |
# run: | | |
# gcloud auth configure-docker europe-docker.pkg.dev --quiet | |
# - name: Build and push | |
# uses: docker/build-push-action@v3 | |
# with: | |
# push: true | |
# tags: europe-west1-docker.pkg.dev/monk-dev-303707/monk-apps-dev/front-cna:latest-${{ needs.check_env.outputs.env_name }} | |
deploy: | |
container: | |
image: dtzar/helm-kubectl:3.6.3 | |
environment: ${{ needs.check_env.outputs.env_name }} | |
runs-on: ubuntu-latest | |
needs: | |
- check_env | |
- build | |
steps: | |
# Setup gcloud CLI | |
- name: "auth" | |
uses: "google-github-actions/auth@v0" | |
with: | |
credentials_json: "${{ secrets.GKE_SA_KEY }}" | |
# Get the GKE credentials so we can deploy to the cluster | |
- uses: google-github-actions/[email protected] | |
with: | |
cluster_name: ${{ secrets.GKE_CLUSTER }} | |
location: ${{ secrets.GKE_ZONE }} | |
project_id: ${{ secrets.GKE_PROJECT }} | |
- name: Download the build artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: build-${{ needs.check_env.outputs.env_name }} | |
path: webapp-${{ needs.check_env.outputs.env_name }} | |
# Deploy to the GKE cluster | |
- name: Clean up old files | |
run: |- | |
kubectl -n poc exec -it $(kubectl get pods -n poc -l app.kubernetes.io/instance=poc-spa --no-headers | awk '{print $1}') -- rm -rf webapp-${{ needs.check_env.outputs.env_name }} | |
- name: Deploy | |
run: |- | |
kubectl -n poc cp webapp-${{ needs.check_env.outputs.env_name }} poc/$(kubectl get pods -n poc -l app.kubernetes.io/instance=poc-spa --no-headers | awk '{print $1}'):/app/ |