Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/auto deploy 6 #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# name: GitHub Actions Demo
# run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
# on: [push]
# jobs:
# Explore-GitHub-Actions:
# runs-on: ubuntu-latest
# steps:
# - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
# - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
# - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
# - name: Check out repository code
# uses: actions/checkout@v3
# - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
# - run: echo "🖥️ The workflow is now ready to test your code on the runner."
# - name: List files in the repository
# run: |
# ls ${{ github.workspace }}
# - run: echo "🍏 This job's status is ${{ job.status }}."



# name: Deploy to AWS

# on:
# push:
# branches:
# - master

# jobs:
# deploy:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code~
# uses: actions/checkout@v2

# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ap-southeast-1

# - name: Deploy to Server 1
# uses: easingthemes/ssh-deploy@main
# env:
# SSH_PRIVATE_KEY: ${ { secrets.EC2_SSH_KEY }}
# REMOTE_HOST: ${ { secrets.HOST_DNS }}
# REMOTE_USER: ${ { secrets.USERNAME }}
# TARGET: ${ { secrets.TARGET_DIR }}
# - name: Deploy pod~
# run: |
# kubectl apply -f petstore.yml



name: Deploy Spring Boot app to EC2

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '8'

- name: Build Spring Boot app
run: mvn clean install -DskipTests
# run: ./mvnw clean package

- name: Install AWS CLI
run: sudo apt-get install awscli

- name: Deploy to EC2
uses: easingthemes/ssh-deploy@v2
with:
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
REMOTE_USER: 'ec2-user'
REMOTE_HOST: ${{ secrets.HOST_DNS }}
remote-path: /home/ubuntu/myapp
local-path: target/myapp.jar
ARGS: --exclude=*.log
# - name: Deploy to EC2 instance
# run: |
# aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws configure set default.region us-west-2
# aws ec2 describe-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID }}
# scp -i ${{ secrets.EC2_SSH_KEY }} target/*.jar ec2-user@${{ secrets.EC2_INSTANCE_IP }}:/home/ec2-user/
# ssh -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_INSTANCE_IP }} 'sudo systemctl stop myapp.service'
# ssh -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_INSTANCE_IP }} 'sudo mv /home/ec2-user/*.jar /opt/myapp/myapp.jar'
# ssh -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_INSTANCE_IP }} 'sudo systemctl start myapp.service'