-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug where
deploy.yml
fails on Docker image deployment
- Loading branch information
1 parent
675bc15
commit c47d92b
Showing
1 changed file
with
38 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,13 @@ name: Deploy mazacofo | |
on: | ||
push: | ||
branches: [ master ] | ||
#pull_request: | ||
#branches: [ master ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create .env file | ||
run: | | ||
touch .env | ||
|
@@ -19,37 +18,54 @@ jobs: | |
echo "MYSQL_PW=$MYSQL_PW" >> .env | ||
echo "MYSQL_DB=$MYSQL_DB" >> .env | ||
echo "WEBHOOK_URL=$WEBHOOK_URL" >> .env | ||
env: | ||
env: | ||
MYSQL_HOST: ${{ secrets.MYSQL_HOST }} | ||
MYSQL_USER: ${{ secrets.MYSQL_USER }} | ||
MYSQL_PW: ${{ secrets.MYSQL_PW }} | ||
MYSQL_DB: ${{ secrets.MYSQL_DB }} | ||
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | ||
- name: Set up Docker Buildx | ||
uses: docker/[email protected] | ||
- name: Login Docker hub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Build and push Docker images | ||
uses: docker/[email protected] | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: dongzoolee/mazacofo:latest | ||
aws-region: ap-northeast-2 | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build and Push image to ECR - client | ||
env: | ||
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
REPOSITORY: mazacofo | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f ./Dockerfile . | ||
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | ||
- name: Deploy to server | ||
uses: appleboy/[email protected] | ||
env: | ||
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
TAG: ${{ github.sha }} | ||
REPOSITORY: mazacofo | ||
PORT_: 2021 | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
username: ${{ secrets.SERVER_USERNAME }} | ||
password: ${{ secrets.SERVER_PASSWORD }} | ||
envs: REGISTRY, TAG, REPOSITORY, PORT_ | ||
script: | | ||
if [ "$( docker container inspect -f '{{.State.Status}}' mazacofo )" == "running" ]; then | ||
docker container stop mazacofo | ||
docker container rm mazacofo | ||
if [ "$( docker container inspect -f '{{.State.Status}}' $REPOSITORY )" == "running" ]; then | ||
docker container stop $REPOSITORY | ||
docker container rm $REPOSITORY | ||
fi | ||
docker image rm dongzoolee/mazacofo | ||
docker pull dongzoolee/mazacofo:latest | ||
docker run -d --name mazacofo -p 2021:2021 dongzoolee/mazacofo | ||
docker image rmi $(docker images '$REGISTRY/$REPOSITORY') | ||
aws ecr get-login-password --region ap-northeast-2 \ | ||
| docker login --username AWS --password-stdin 889566267001.dkr.ecr.ap-northeast-2.amazonaws.com | ||
docker pull $REGISTRY/$REPOSITORY:$TAG | ||
docker run -d --name $REPOSITORY -p $PORT_:$PORT_ $REGISTRY/$REPOSITORY:$TAG |