Skip to content

chore: Dockerfile 변경 #31

chore: Dockerfile 변경

chore: Dockerfile 변경 #31

Workflow file for this run

name: deploy action
on:
push:
branches:
- chore/250
env:
REGISTRY: "docker.io"
NAMESPACE: "clean01"
IMAGE_NAME: "layer-server"
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
jobs:
setup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
steps:
- name: Setup Env
id: set-env
run: |
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "DEPLOY_TARGET=production" >> $GITHUB_OUTPUT
else
echo "DEPLOY_TARGET=aws" >> $GITHUB_OUTPUT
fi
build:
name: build
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
REGISTRY: "docker.io"
NAMESPACE: "clean01"
IMAGE_NAME: "layer-server"
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
APPLICATION_SECRET_PROPERTIES: ${{ secrets.APPLICATION_SECRET_PROPERTIES }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
- name: Create application-secret.properties
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./${{ env.MODULE }}/src/main/resources/application-secret.properties
- name: Build ${{ env.MODULE }} module
run: ./gradlew :${{ env.MODULE }}:build
- name: Run tests:${{ env.MODULE }}
run: ./gradlew :${{ env.MODULE }}:test
- name: Docker Hub Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_EMAIL }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_${{ env.MODULE }}
- name: push
uses: docker/build-push-action@v4
with:
context: ./${{ env.MODULE }}
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_${{ env.MODULE }}:latest
# ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}/${{ env.MODULE }}:latest
# ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}/${{ env.MODULE }}:${{ github.run_id }}
deploy:
name: Deploy
needs: [ build, setup ]
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Create application-secret.properties file
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
- name: Send Docker Compose
uses: appleboy/scp-action@master
with:
host: ${{secrets.AWS_INSTANCE_HOST}}
username: ubuntu
key: ${{secrets.AWS_INSTANCE_PEM}}
port: 22
source: ./${{ env.MODULE }}/infra/aws/*
target: "/home/ubuntu"
- name: Deploy with Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_INSTANCE_HOST }}
username: ubuntu
key: ${{secrets.AWS_INSTANCE_PEM}}
port: 22
script: |
sudo apt install docker-ce
sudo docker login --username ${{secrets.DOCKER_EMAIL}} --password ${{secrets.DOCKER_PASSWORD}}
cd /home/ubuntu/${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > application-secret.properties
sudo docker-compose pull && sudo docker-compose up -d
sudo docker image prune -a -f