add docs (#65) #155
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 | |
on: | |
push: | |
branches: | |
- 'main' | |
workflow_dispatch: | |
jobs: | |
dh-build: | |
name: Docker Hub Build and Push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DH_USER }} | |
password: ${{ secrets.DH_TOKEN }} | |
- name: Build | |
run: | | |
docker build -f shortener/Dockerfile -t dbut2/shortener shortener | |
- name: Tag and Push SHA | |
run: | | |
docker tag dbut2/shortener dbut2/shortener:${{ github.sha }} | |
docker push dbut2/shortener:${{ github.sha }} | |
- name: Tag and Push latest | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
docker tag dbut2/shortener dbut2/shortener:latest | |
docker push dbut2/shortener:latest | |
env-test: | |
name: Build and Deploy TEST | |
if: github.event_name == 'workflow_dispatch' | |
environment: | |
name: test | |
url: https://test.but.la/shorten | |
runs-on: ubuntu-latest | |
needs: | |
- dh-build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: gcloud Auth | |
id: auth | |
uses: "google-github-actions/auth@v0" | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
token_format: 'access_token' | |
- name: Login to gcr | |
run: | | |
echo "${{ steps.auth.outputs.access_token }}" | docker login -u oauth2accesstoken --password-stdin https://asia.gcr.io | |
- name: Build and Push | |
run: | | |
docker build -f deployment/Dockerfile -t asia.gcr.io/but-la/shortener/test --build-arg ENV=test --build-arg BASE_IMAGE=dbut2/shortener:${{ github.sha }} deployment | |
docker tag asia.gcr.io/but-la/shortener/test asia.gcr.io/but-la/shortener/test:${{ github.sha }} | |
docker push asia.gcr.io/but-la/shortener/test:${{ github.sha }} | |
docker tag asia.gcr.io/but-la/shortener/test asia.gcr.io/but-la/shortener/test:latest | |
docker push asia.gcr.io/but-la/shortener/test:latest | |
- name: Deploy | |
uses: "google-github-actions/deploy-cloudrun@v1" | |
with: | |
project_id: but-la | |
region: australia-southeast2 | |
secrets: | | |
DATABASE=database-config:latest | |
DATASTORE=datastore-config:latest | |
REDIS=redis-config:latest | |
service: shortener-test | |
image: asia.gcr.io/but-la/shortener/test:${{ github.sha }} | |
env-dev: | |
name: Build and Deploy DEV | |
if: github.ref == 'refs/heads/main' | |
environment: | |
name: dev | |
url: https://dev.but.la/shorten | |
runs-on: ubuntu-latest | |
needs: | |
- dh-build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: gcloud Auth | |
id: auth | |
uses: "google-github-actions/auth@v0" | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
token_format: 'access_token' | |
- name: Login to gcr | |
run: | | |
echo "${{ steps.auth.outputs.access_token }}" | docker login -u oauth2accesstoken --password-stdin https://asia.gcr.io | |
- name: Build and Push | |
run: | | |
docker build -f deployment/Dockerfile -t asia.gcr.io/but-la/shortener/dev --build-arg ENV=dev --build-arg BASE_IMAGE=dbut2/shortener:${{ github.sha }} deployment | |
docker tag asia.gcr.io/but-la/shortener/dev asia.gcr.io/but-la/shortener/dev:${{ github.sha }} | |
docker push asia.gcr.io/but-la/shortener/dev:${{ github.sha }} | |
docker tag asia.gcr.io/but-la/shortener/dev asia.gcr.io/but-la/shortener/dev:latest | |
docker push asia.gcr.io/but-la/shortener/dev:latest | |
- name: Deploy | |
uses: "google-github-actions/deploy-cloudrun@v1" | |
with: | |
project_id: but-la | |
region: australia-southeast2 | |
secrets: | | |
DATABASE=database-config:latest | |
DATASTORE=datastore-config:latest | |
REDIS=redis-config:latest | |
service: shortener-dev | |
image: asia.gcr.io/but-la/shortener/dev:${{ github.sha }} | |
env-prod: | |
name: Build and Deploy PROD | |
environment: | |
name: prod | |
url: https://but.la/shorten | |
runs-on: ubuntu-latest | |
needs: | |
- dh-build | |
- env-dev | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: gcloud Auth | |
id: auth | |
uses: "google-github-actions/auth@v0" | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
token_format: 'access_token' | |
- name: Login to gcr | |
run: | | |
echo "${{ steps.auth.outputs.access_token }}" | docker login -u oauth2accesstoken --password-stdin https://asia.gcr.io | |
- name: Build and Push | |
run: | | |
docker build -f deployment/Dockerfile -t asia.gcr.io/but-la/shortener/prod --build-arg ENV=prod --build-arg BASE_IMAGE=dbut2/shortener:${{ github.sha }} deployment | |
docker tag asia.gcr.io/but-la/shortener/prod asia.gcr.io/but-la/shortener/prod:${{ github.sha }} | |
docker push asia.gcr.io/but-la/shortener/prod:${{ github.sha }} | |
docker tag asia.gcr.io/but-la/shortener/prod asia.gcr.io/but-la/shortener/prod:latest | |
docker push asia.gcr.io/but-la/shortener/prod:latest | |
- name: Deploy | |
uses: "google-github-actions/deploy-cloudrun@v1" | |
with: | |
project_id: but-la | |
region: australia-southeast2 | |
secrets: | | |
DATABASE=database-config:latest | |
DATASTORE=datastore-config:latest | |
REDIS=redis-config:latest | |
service: shortener-prod | |
image: asia.gcr.io/but-la/shortener/prod:${{ github.sha }} |