Skip to content

Commit

Permalink
chore: Dockerfile 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
clean2001 committed Oct 26, 2024
1 parent 258358d commit 71f8c3b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
65 changes: 37 additions & 28 deletions .github/workflows/aws-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
REGISTRY: "docker.io"
NAMESPACE: "clean01"
IMAGE_NAME: "layer-server"
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"

jobs:
setup:
Expand Down Expand Up @@ -42,9 +40,6 @@ jobs:
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 }}

Expand All @@ -63,13 +58,20 @@ jobs:

- name: Create application-secret.properties
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./${{ env.MODULE }}/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
- name: Build ${{ env.MODULE }} module
run: ./gradlew :${{ env.MODULE }}:build
- name: Build layer-api module
run: ./gradlew :layer-api:build

- name: Run tests:${{ env.MODULE }}
run: ./gradlew :${{ env.MODULE }}:test
- name: Test layer-api module
run: ./gradlew :layer-api:test

- name: Build layer-batch module
run: ./gradlew :layer-batch:build

- name: Test layer-batch module
run: ./gradlew :layer-batch:test

- name: Docker Hub Login
uses: docker/login-action@v1
Expand All @@ -81,59 +83,66 @@ jobs:
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_${{ env.MODULE }}
images: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
- name: push
- name: Push layer-api Docker Image
uses: docker/build-push-action@v4
with:
context: ./${{ env.MODULE }}
context: ./layer-api
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 }}
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest
- name: Push layer-batch Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-batch
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
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
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
- name: Send Docker Compose
uses: appleboy/scp-action@master
with:
host: ${{secrets.AWS_INSTANCE_HOST}}
host: ${{ secrets.AWS_INSTANCE_HOST }}
username: ubuntu
key: ${{secrets.AWS_INSTANCE_PEM}}
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
source: ./${{ env.MODULE }}/infra/aws/*
source: "./layer-api/infra/aws/*,./layer-batch/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}}
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 login --username ${{ secrets.DOCKER_EMAIL }} --password ${{ secrets.DOCKER_PASSWORD }}
cd /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
sudo docker-compose pull && sudo docker-compose up -d
cd /home/ubuntu/layer-batch/infra/${{ env.DEPLOY_TARGET }}
sudo docker-compose pull && sudo docker-compose up -d
sudo docker image prune -a -f
sudo docker image prune -a -f
15 changes: 14 additions & 1 deletion layer-api/infra/aws/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@ services:
- "8080:8080"
environment:
- TZ=Asia/Seoul
- SPRING_PROFILES_ACTIVE=aws # 변경
- SPRING_PROFILES_ACTIVE=aws
volumes:
- ./application-secret.properties:/config/application-secret.properties
- ./log:/log
- ./tokens:/config/tokens
networks:
- app-network

batch-job:
image: docker.io/clean01/layer-server_layer-batch:latest
container_name: layer-batch
environment:
- TZ=Asia/Seoul
volumes:
- ./application-secret.properties:/config/application-secret.properties
- ./log:/log
networks:
- app-network
depends_on:
- java-app

nginx:
image: nginx:latest
container_name: nginx
Expand Down

0 comments on commit 71f8c3b

Please sign in to comment.