Skip to content

Commit

Permalink
[Feature/BAR-140] 기존 도커 이미지 삭제 및 빌드 실패 해결 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
miro-ring authored Jan 12, 2024
1 parent 5af9f0c commit 699e543
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 46 deletions.
72 changes: 41 additions & 31 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }}
AWS_REGION: ap-northeast-2
IMAGE_NAME: baro

jobs:
Expand All @@ -18,39 +19,48 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ env.IMAGE_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Delete old docker image in ECR
uses: LeiaInc/devops-delete-old-aws-ecr-images@v1
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
repo-name: ${{ env.IMAGE_NAME }}
qtd-images: 5

- name: Deploy to EC2

run: |
echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > private_key.pem
chmod 400 private_key.pem
ssh -i private_key.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_PUBLIC_DOMAIN }} "
aws ecr get-login-password --region ap-northeast-2 |
sudo docker login --username AWS --password-stdin ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} &&
if [ \$(sudo docker ps -q -f name=${{ env.IMAGE_NAME }}) ]; then
sudo docker stop ${{ env.IMAGE_NAME }} &&
sudo docker rm ${{ env.IMAGE_NAME }}
fi &&
sudo docker image pull ${{ steps.meta.outputs.tags }} &&
sudo docker container run --name ${{ env.IMAGE_NAME }} -d -p 3000:3000 ${{ steps.meta.outputs.tags }}"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ env.IMAGE_NAME }}
IMAGE_TAG: ${{ github.sha }}
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_DOMAIN }}
username: ubuntu
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
envs: REGISTRY,REPOSITORY,IMAGE_TAG,AWS_REGION,IMAGE_NAME
script: |-
aws ecr get-login-password --region ${{ env.AWS_REGION }} |
sudo docker login --username AWS --password-stdin ${{ env.REGISTRY }}/${{ env.REPOSITORY }}
sudo docker stop ${{ env.IMAGE_NAME }} || true
sudo docker rm ${{ env.IMAGE_NAME }} || true
sudo docker rmi $(sudo docker images -aq) || true
sudo docker pull $REGISTRY/$REPOSITORY:$IMAGE_TAG
sudo docker container run --name ${{ env.IMAGE_NAME }} -d -p 3000:3000 $REGISTRY/$REPOSITORY:$IMAGE_TAG
10 changes: 3 additions & 7 deletions src/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ instance.interceptors.response.use(
}

// 서버 에러 캐치
if (error.status > 500) {
if (error.status && error.status > 500) {
return Promise.reject<BaroErrorType>({
status: error.status,
message: '',
});
}

return Promise.reject<BaroErrorType>(error);
},
);

Expand All @@ -55,8 +53,6 @@ export const http = {
param?: ParamType,
options?: AxiosRequestConfig,
): Promise<AxiosResponse<ResponseType>> => instance.put(url, param, options),
delete: <ParamType, ResponseType>(
url: string,
param?: ParamType,
): Promise<AxiosResponse<ResponseType>> => instance.delete(url, param),
delete: <ResponseType>(url: string): Promise<AxiosResponse<ResponseType>> =>
instance.delete(url),
};
7 changes: 2 additions & 5 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import clsx from 'clsx';

import * as styles from './style.css';

interface ButtonProps
extends RecipeVariants<typeof styles.button>,
PropsWithChildren<ComponentPropsWithoutRef<'button'>> {
onClick: () => void;
}
type ButtonProps = RecipeVariants<typeof styles.button> &
PropsWithChildren<ComponentPropsWithoutRef<'button'>>;

const Button = ({
children,
Expand Down
5 changes: 4 additions & 1 deletion src/components/Input/WriteInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const WriteInput = ({
}: WriteInputProps) => {
const { id, value } = inputProps;
const inputRef = useRef<HTMLTextAreaElement | null>(null);
const [textareaHeight, setTextareaHeight] = useState({
const [textareaHeight, setTextareaHeight] = useState<{
row: number;
lineBreak: Record<number, boolean>;
}>({
row: 1,
lineBreak: {},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/Portal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface PortalProps {
}

const Portal = ({ children, id }: PortalProps) => {
const root = document.getElementById(id);
const root = document.getElementById(id) as HTMLDivElement;

return ReactDOM.createPortal(children, root);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tooltip/TooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TooltipContent = ({ children }: PropsWithChildren) => {
<div
className={clsx(
styles.content({ hasArrow }),
hasArrow && ARROW_STYLE[placement],
hasArrow && placement && ARROW_STYLE[placement],
)}
style={assignInlineVars({
[styles.top]: `${position.top}px`,
Expand Down

0 comments on commit 699e543

Please sign in to comment.