fix: working directiory error #8
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
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'fluentbit/**' | |
env: | |
AWS_REGION: ap-northeast-2 | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
DEV_ECR_REPOSITORY: ${{ secrets.DEV_FLUENTBIT_ECR_REPOSITORY }} | |
PROD_ECR_REPOSITORY: ${{ secrets.PROD_FLUENTBIT_ECR_REPOSITORY }} | |
IMAGE_TAG: latest | |
jobs: | |
login-to-aws-ecr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
# role-to-assume: "arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions" | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: login to ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: 'false' | |
# outputs: | |
# registry: ${{ steps.login-ecr.outputs.registry }} | |
# docker_username: ${{ steps.login-ecr.outputs.username }} | |
# docker_password: ${{ steps.login-ecr.outputs.password }} | |
build-and-push: | |
runs-on: ubuntu-latest | |
needs: login-to-aws-ecr | |
env: | |
working-directory: ./fluentbit | |
steps: | |
- name: Build and push image to Amazon ECR (dev) | |
run: | | |
docker build -t ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.DEV_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} . | |
docker push ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.DEV_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
working-directory: ${{ env.working-directory }} | |
- name: Build and push image to Amazon ECR (prod) | |
run: | | |
docker build -t ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.PROD_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} . | |
docker push ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.PROD_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
working-directory: ${{ env.working-directory }} | |
- name: Pull image from Amazon ECR and restart container in EC2 (dev) | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.DEV_SERVER_SSH_KEY }} | |
host: ${{ secrets.DEV_SERVER_HOST }} | |
username: ${{ secrets.DEV_SERVER_USER }} | |
script: | | |
docker pull ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.DEV_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
docker stop fluentbit-dev && docker rm fluentbit-dev | |
docker run -d --name fluentbit-dev -p 8888:8888 -p 8889:8889 | | |
--network dev-network | | |
-e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY }} | | |
-e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} | | |
-e env=dev | | |
${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.DEV_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} |