-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
569235d
commit f540bcb
Showing
4 changed files
with
93 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: deploy | ||
on: | ||
push: | ||
branches: | ||
- "**" | ||
# on: | ||
# push: | ||
# branches: | ||
# - master | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Utilities | ||
run: sudo apt-get install -y jq | ||
- name: Install AWS Client and LightsailControl Plugin | ||
run: | | ||
aws --version | ||
curl "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl" -o "lightsailctl" | ||
sudo mv "lightsailctl" "/usr/local/bin/lightsailctl" | ||
sudo chmod +x /usr/local/bin/lightsailctl | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-northeast-1 | ||
- name: Build Docker Image | ||
run: | | ||
docker build -t stationapi:latest . | ||
- name: Push and Deploy | ||
env: | ||
SERVICE_NAME: ${{ secrets.SERVICE_NAME }} | ||
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }} | ||
MYSQL_USER: ${{ secrets.MYSQL_USER }} | ||
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} | ||
MYSQL_HOST: ${{ secrets.MYSQL_HOST }} | ||
run: sh ./scripts/generate-aws-container-json.sh |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"serviceName": $SERVICE_NAME, | ||
"containers": { | ||
"api": { | ||
"image": $IMAGE, | ||
"command": [["sh", "./scripts/start.prod.sh"]], | ||
"environment": { | ||
"MYSQL_DATABASE": $MYSQL_DATABASE, | ||
"MYSQL_PASSWORD": $MYSQL_PASSWORD, | ||
"MYSQL_USER": $MYSQL_USER, | ||
"MYSQL_HOST": $MYSQL_HOST | ||
}, | ||
"ports": { "3000": "HTTP" } | ||
} | ||
}, | ||
"publicEndpoint": { | ||
"containerName": "api", | ||
"containerPort": 3000, | ||
"healthCheck": { | ||
"healthyThreshold": 2, | ||
"unhealthyThreshold": 2, | ||
"timeoutSeconds": 3, | ||
"intervalSeconds": 3, | ||
"path": "/graphql", | ||
"successCodes": "200-499" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
JSON_TEMPLATE=$(cat ./scripts/aws-container-template.json) | ||
|
||
SERVICE_NAME=stationapi | ||
aws lightsail push-container-image \ | ||
--region ap-northeast-1 \ | ||
--service-name ${SERVICE_NAME} \ | ||
--label api \ | ||
--image stationapi:latest | ||
IMAGE=$(aws lightsail get-container-images --service-name ${SERVICE_NAME} | jq --raw-output ".containerImages[0].image") | ||
JSON_STRING=$(jq -n \ | ||
--arg IMAGE "$IMAGE" \ | ||
--arg SERVICE_NAME "$SERVICE_NAME" \ | ||
--arg MYSQL_DATABASE "$MYSQL_DATABASE" \ | ||
--arg MYSQL_USER "$MYSQL_USER" \ | ||
--arg MYSQL_PASSWORD "$MYSQL_PASSWORD" \ | ||
--arg MYSQL_HOST "$MYSQL_HOST" \ | ||
"$JSON_TEMPLATE" | ||
) | ||
echo $JSON_STRING > aws-container.json | ||
aws lightsail create-container-service-deployment --service-name ${SERVICE_NAME} --cli-input-json file://$(pwd)/aws-container.json |