Skip to content

fix(deploy): update workflows #1 #17

fix(deploy): update workflows #1

fix(deploy): update workflows #1 #17

Workflow file for this run

name: Deploy to Google Cloud VM with Docker
on:
push:
branches:
- feat/docker
paths-ignore:
- README.md
- .gitignore
pull_request_target:
branches:
- master
types:
- closed
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Docker Hub Authentication
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest .
- name: Tag Docker Image
run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest
- name: Push Docker Image to Docker Hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest
deploy:
runs-on: ubuntu-latest
needs: publish
steps:
- name: Set up Cloud CLI
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ secrets.GCE_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
export_default_credentials: true
- name: Access gcloud CLI
run: |
gcloud auth configure-docker
- name: Checkout repository
uses: actions/checkout@v3
- name: Copy docker-compose.yml into GCP Instance
uses: appleboy/scp-action@master
with:
host: ${{ secrets.GCP_VM_IP }}
username: ${{ secrets.GCP_USER }}
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
source: 'docker-compose.yml'
target: '/home/${{ secrets.GCP_USER }}/docker-compose.yml'
- name: SSH into GCP and Run Docker Container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.GCP_VM_IP }}
username: ${{ secrets.GCP_USER }}
key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
script: |
echo "hello this is from gcp vm"