Skip to content

Deploy Application

Deploy Application #31

Workflow file for this run

name: Deployment to EC2
env:
DOCKERHUB_USERNAME: deahtstroke
on:
workflow_dispatch:
jobs:
build-and-package:
runs-on: ubuntu-latest
steps:
- name: Checkout the project
uses: actions/checkout@v4
- name: List the files
run: ls
- name: Set up JDK 17 for x64
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
architecture: x64
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run the Gradle Build
run: ./gradlew clean build
- name: Set Project name and version as environment variables
run: |
echo "${{ env.DOCKERHUB_USERNAME}}/$(./gradlew -q projectName):$(./gradlew -q version)" > imageName.txt
cat imageName.txt
- name: Upload Docker Image Name as Artifact
uses: actions/upload-artifact@v3
with:
name: docker-image-name
path: |
imageName.txt
build/libs/**
dockerize-and-upload:
needs: build-and-package
runs-on: ubuntu-latest
steps:
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download Image Name File
uses: actions/download-artifact@v3
with:
name: docker-image-name
- name: List artifact files
run: ls -R
- name: Set variable with docker image name
run: |
content=$(cat ./imageName.txt)
echo "DOCKER_IMAGE_NAME=$content" >> $GITHUB_ENV
shell: bash
- name: Find and set JAR file
id: find_jar_file
run: |
JAR_FILE=$(find ./build/libs -type f -name "destiny2bot-*.jar")
if [ -z "$JAR_FILE" ]; then
echo "::debug::No JAR file found in build/libs with the specified pattern"
exit 1
fi
echo "JAR_FILE=$JAR_FILE" >> $GITHUB_OUTPUT
shell: bash
- name: Build and Push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ env.DOCKER_IMAGE_NAME }}
build-args: JAR_FILE=${{ steps.find_jar_file.output.JAR_FILE }}
EC2-and-Docker-Compose:
needs: dockerize-and-upload
runs-on: ubuntu-latest
steps:
- name: Connect to EC2 instance
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_PRIVATE_KEY }}
script: whoami