fix: login/logout #16
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
name: Build and Deploy Server | |
on: push | |
env: | |
ECR_REPOSITORY: colonizer-mahjong-server | |
ECS_SERVICE: colonizer-mahjong-server | |
ECS_CLUSTER: colonizer-mahjong | |
DOCKERFILE: "./server.dockerfile" | |
jobs: | |
build-docker-image-dev: | |
if: ${{ github.ref != 'refs/heads/main' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v2 | |
- name: Make .env | |
run: | | |
touch ./src/config.ts | |
echo '${{ secrets.SERVER_CONFIG }}' >> ./src/config.ts | |
touch ./prisma/.env | |
echo '${{ secrets.SERVER_PRISMA_ENV }}' >> ./prisma/.env | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
- name: Build | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ${{ env.DOCKERFILE }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-docker-image-stable: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v2 | |
- run: | | |
ref="${github_ref////-}" | |
echo $ref | |
echo "::set-env name=ref::$ref" | |
env: | |
github_ref: ${{ github.ref }} | |
ACTIONS_ALLOW_UNSECURE_COMMANDS: true | |
- name: Make .env | |
run: | | |
touch ./src/config.ts | |
echo '${{ secrets.SERVER_CONFIG }}' >> ./src/config.ts | |
touch ./prisma/.env | |
echo '${{ secrets.SERVER_PRISMA_ENV }}' >> ./prisma/.env | |
- 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-2 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Copy credentials to Docker Buildx | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ steps.login-ecr.outputs.registry }} | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
- name: Build, tag and push | |
uses: docker/build-push-action@v4 | |
env: | |
ECR: ${{ steps.login-ecr.outputs.registry }} | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.ECR }}/${{ env.ECR_REPOSITORY }}:stable | |
${{ env.ECR }}/${{ env.ECR_REPOSITORY }}:latest | |
file: ${{ env.DOCKERFILE }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Download task definition | |
run: | | |
aws ecs describe-task-definition --task-definition ${{ env.ECS_SERVICE }} --query taskDefinition > task-definition.json | |
- name: Render Amazon ECS task definition | |
id: render-container | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: task-definition.json | |
container-name: ${{ env.ECS_SERVICE }} | |
image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:stable | |
- name: Deploy to Amazon ECS service | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.render-container.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE }} | |
cluster: ${{ env.ECS_CLUSTER }} |