Skip to content

Update Dockerfile

Update Dockerfile #2

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for Gradle
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Build Docker Image
run: |
docker build -t ${{ secrets.IMAGE_NAME }} .
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Push Docker Image to Docker Hub
run: |
docker push ${{ secrets.IMAGE_NAME }}
- name: Deploy to Backend EC2 through Bastion Host
env:
BASTION_HOST: ${{ secrets.BASTION_HOST }}
TARGET_HOST: ${{ secrets.EC2_HOST }}
USER: ${{ secrets.EC2_USER }}
SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
run: |
echo "$SSH_KEY" | tr -d '\r' > hackathon.pem
chmod 600 hackathon.pem
ssh -o StrictHostKeyChecking=no -i hackathon.pem $USER@$BASTION_HOST << 'EOF'
ssh -o StrictHostKeyChecking=no -i hackathon.pem $USER@${{ secrets.EC2_HOST }} << 'INNER_EOF'
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
docker pull ${{ secrets.IMAGE_NAME }}
if [ $(docker ps -a -q -f name= gratitude-container) ]; then
docker stop gratitude-container || true
docker rm gratitude-container || true
fi
docker run -d --name gratitude-container -p 8080:8080 ${{ secrets.IMAGE_NAME }}
INNER_EOF
EOF
rm hackathon.pem