Skip to content

Commit

Permalink
dockerization & deployment (#78)
Browse files Browse the repository at this point in the history
* add docker relates

* udpate docker script

* one step dockerfile

* add .env relates

* npm audit fix

* sync gh action pattern

* update endpoint

* update dockerfile

* setup nginx config

* use npm ci

* update people api endpoint

* update gh action

* dockerization final

* copy dotenv

* update docker cmd

* update dockerfile

* update docker stack

* people tags, badges

* tags, badges null handling

* update PersonCard null
  • Loading branch information
BlueHorn07 authored Oct 8, 2023
1 parent 4c4277e commit cec7626
Show file tree
Hide file tree
Showing 11 changed files with 7,392 additions and 6,360 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# add git-ignore syntax here of things you don't want copied into docker image

.git
*Dockerfile*
*docker-compose*
node_modules

.env
.github
.husky
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GATSBY_API_URL="https://api.poapper.club"
32 changes: 0 additions & 32 deletions .github/workflows/build.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
release:
types: [published]

name: Docker Build and Push

env:
ECR_REGISTRY: 151345152001.dkr.ecr.ap-northeast-2.amazonaws.com
ECR_REPOSITORY: poapper-homepage

jobs:
docker_build_and_push:
name: Docker build and push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Determine Prod/Dev Stage
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
echo "PROD"
echo "IMAGE_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
else
echo "DEV"
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
fi
- name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
push: true

deploy_health_check:
name: Check Application Status
needs: docker_build_and_push
runs-on: ubuntu-latest
steps:
- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v3
with:
url: https://poapper.club|https://dev.poapper.club
follow-redirect: true
max-attempts: 3
retry-delay: 10s
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:16.20-alpine AS builder

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm ci

COPY . .
COPY .env.production .env

RUN npm run build

# serving stage
FROM nginx

EXPOSE 80

COPY --from=builder /usr/src/app/public /usr/share/nginx/html
32 changes: 32 additions & 0 deletions docker-stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.3'
services:
dev:
image: 151345152001.dkr.ecr.ap-northeast-2.amazonaws.com/poapper-homepage:latest
ports:
- 9001:80
logging:
driver: local
options:
max-size: 10m
deploy:
labels:
swarmpit.service.deployment.autoredeploy: 'true'
placement:
constraints:
- node.role != manager
- node.labels.application == poapper_web
prod:
image: 151345152001.dkr.ecr.ap-northeast-2.amazonaws.com/poapper-homepage:vX.X.X
ports:
- 9000:80
logging:
driver: local
options:
max-size: 10m
deploy:
labels:
swarmpit.service.deployment.autoredeploy: 'true'
placement:
constraints:
- node.role != manager
- node.labels.application == poapper_web
11 changes: 11 additions & 0 deletions nginx/poapper-dev.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
server_name dev.poapper.club;
client_max_body_size 10M;

location / {
proxy_pass http://localhost:9001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
11 changes: 11 additions & 0 deletions nginx/poapper.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
server_name poapper.club;
client_max_body_size 10M;

location / {
proxy_pass http://localhost:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Loading

0 comments on commit cec7626

Please sign in to comment.