Skip to content

Commit

Permalink
add build and deploy github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kraiviks committed Mar 13, 2024
1 parent 87c8459 commit 20cd9d2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Deploy

on:
push:
branches:
- main

jobs:
build:
name: Build and Push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to Docker registry
run: echo "${{ secrets.CI_REGISTRY_PASSWORD }}" | docker login -u ${{ secrets.CI_REGISTRY_USER }} --password-stdin ${{ secrets.CI_REGISTRY }}

- name: Build Docker image
run: |
docker build -t ${{ secrets.CI_REGISTRY_IMAGE }}:${{ github.sha }} -t ${{ secrets.CI_REGISTRY_IMAGE }}:latest -f ./deployments/Dockerfile .
- name: Push Docker image
run: |
docker push ${{ secrets.CI_REGISTRY_IMAGE }}:latest
docker push ${{ secrets.CI_REGISTRY_IMAGE }}:${{ github.sha }}
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Login to Docker registry
run: echo "${{ secrets.CI_REGISTRY_PASSWORD }}" | docker login -u ${{ secrets.CI_REGISTRY_USER }} --password-stdin ${{ secrets.CI_REGISTRY }}

- name: Deploy Docker container
run: docker run -d -p 8000:8001 ${{ secrets.CI_REGISTRY_IMAGE }}:latest
13 changes: 13 additions & 0 deletions deployments/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# build environment
FROM node:20.10-alpine as build
WORKDIR /app
COPY .. .
RUN yarn
RUN yarn build

# production environment
FROM nginx:stable-alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY --from=build /app/deployments/nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
8 changes: 8 additions & 0 deletions deployments/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}

0 comments on commit 20cd9d2

Please sign in to comment.