Update deploy-dev.sh #247
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: develop cd | |
on: | |
push: | |
branches: [ "develop" ] | |
permissions: | |
checks: write | |
pull-requests: write | |
jobs: | |
INSTALL_DOCKER: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Remote Check and install Docker | |
uses: appleboy/ssh-action@master | |
with: | |
username: ${{ secrets.USERNAME }} | |
host: ${{ secrets.HOST_DEV }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
port: 22 | |
script: | | |
if ! [ -x "$(command -v docker)" ]; then | |
echo "Docker is not installed. Installing Docker..." | |
sudo yum update | |
sudo amazon-linux-extras install docker | |
sudo systemctl enable --now docker | |
sudo usermod -aG docker $USER | |
else | |
echo "Docker is already installed." | |
fi | |
if ! [ -x "$(command -v docker-compose)" ]; then | |
echo "Docker Compose is not installed. Installing Docker Compose..." | |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
else | |
echo "Docker Compose is already installed." | |
fi | |
MOVE_FILE: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout branch | |
uses: actions/checkout@v3 | |
- name: create dir | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
key: ${{ secrets.PRIVATE_KEY }} | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
mkdir -p /home/app/nginx/ | |
- name: Copy configruation files | |
run: | |
echo "${{secrets.DEVELOP_ENV_FILE }}" > ./.env | |
- name: Send env file | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
source: "./.env" | |
target: "/home/app" | |
- name: Send docker-compose.yml | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
source: "./docker-compose.yml" | |
target: "/home/app" | |
- name: Send deploy-dev.sh | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
source: "./deploy-dev.sh" | |
target: "/home/app" | |
- name: Send nginx.conf | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
source: "./nginx/default.conf" | |
target: "/home/app" | |
CD: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout branch | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: set up environment Variable | |
run: | | |
echo "${{secrets.DEVELOP_ENV_FILE }}" > ./.env | |
echo "${{secrets.APPLICATION_TEST}}" >> ./src/test/resources/application-test.yml | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v2 | |
- name: Setup Gradle permission | |
run: chmod +x ./gradlew | |
- name: Set Up With Run MySQL Docker Container | |
run: | | |
sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE=dadok_test --env MYSQL_ROOT_PASSWORD=${{ secrets.TEST_DB_PASSWORD }} mysql:8.0.31 | |
- name: Set Up With Run Redis | |
run: | | |
sudo docker run --name dadok-redis -p 6379:6379 -d redis --requirepass ${{ secrets.TEST_REDIS_PASSWORD }} | |
- name: build with Gradle | |
run: | | |
./gradlew clean | |
./gradlew build | |
./gradlew bootjar | |
- name: docker hub push | |
run: | | |
pwd | |
ls | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
docker build -t ${{ secrets.DOCKER_DEV_REPO }}:latest . | |
docker push ${{ secrets.DOCKER_DEV_REPO }} | |
- name: Deploy to develop | |
uses: appleboy/ssh-action@master | |
id: deploy-dev | |
if: contains(github.ref, 'develop') | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ${{ secrets.USERNAME }} | |
port: 22 | |
password: ${{ secrets.HOST_PASSWORD }} | |
# key: ${{ secrets.PRIVATE_KEY }} | |
source: "docker-compose.yml" | |
script: | | |
cd /home/app | |
sudo docker pull ${{ secrets.DOCKER_DEV_REPO }} | |
chmod 777 ./deploy-dev.sh | |
./deploy-dev.sh | |
docker rmi $(docker images -aq) | |
echo "end deploy###" |