BE/CD - [DEV] Build & Deploy #185
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: BE/CD - [DEV] Build & Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: be/develop | |
jobs: | |
build: | |
environment: dev | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: backend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.SUBMODULE_PAT }} | |
fetch-depth: 0 | |
submodules: true | |
- name: Set timezone to Korea | |
uses: szenius/[email protected] | |
with: | |
timezoneLinux: "Asia/Seoul" | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
with: | |
cache-write-only: true | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Get current date and time | |
id: datetime | |
run: | | |
echo "datetime=$(date +'%Y%m%d%H%M%S')" >> "$GITHUB_OUTPUT" | |
- name: Image build and push | |
run: | | |
docker build --build-arg PROFILE=dev -t ${{ secrets.DOCKER_REPO_NAME }}/cruru:dev-${{ steps.datetime.outputs.datetime }} --platform linux/arm64 . | |
docker push ${{ secrets.DOCKER_REPO_NAME }}/cruru:dev-${{ steps.datetime.outputs.datetime }} | |
- name: Upload docker-compose yaml script to artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: docker-compose | |
path: | | |
${{ github.workspace }}/backend/docker-compose.dev.yml | |
${{ github.workspace }}/backend/promtail-config.yml | |
outputs: | |
BUILD_VERSION: ${{ steps.datetime.outputs.datetime }} | |
deploy: | |
environment: dev | |
runs-on: [self-hosted, be-dev] | |
needs: build | |
steps: | |
- name: Checkout private repository for deploy files | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ secrets.PRIVATE_REPOSITORY_URL }} | |
token: ${{ secrets.SUBMODULE_PAT }} | |
fetch-depth: 0 | |
path: dev-files | |
- name: Extract secrets as .env file | |
run: | | |
cat <<EOF > ./dev-files/develop/.env | |
# Docker Hub info from Github Secrets | |
DOCKER_IMAGE_VERSION_TAG=dev-${{ needs.build.outputs.BUILD_VERSION }} | |
EOF | |
- name: Stop and remove existing application container | |
run: | | |
sudo docker-compose -f ./dev-files/develop/docker-compose.dev.yml --env-file ./dev-files/develop/.env down --rmi all | |
- name: Run application Server container | |
run: | | |
sudo docker-compose -f ./dev-files/develop/docker-compose.dev.yml --env-file ./dev-files/develop/.env up -d |