Skip to content

feat: combine docker ui and api #9

feat: combine docker ui and api

feat: combine docker ui and api #9

Workflow file for this run

# The name of the workflow.
name: Build and Deploy
# Run the workflow when code is pushed to the main branch
on:
push:
branches:
- main
# Set environment variables
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
# This is the workflow that is being run.
jobs:
build-and-deploy:
# This is telling GitHub to run the workflow on the latest version of Ubuntu.
runs-on: ubuntu-latest
steps:
# Checkout the code from the GitHub repository
- name: Checkout code
uses: actions/checkout@v3
# Install dependencies and run tests for the client application
- name: Install Client
working-directory: ./ui
run: |
cd ui
npm install
npm run build
# Install dependencies, export environment variables to be used by application and run tests for the server application
- name: Install Server
working-directory: ./api
run: |
cd api
npm install
export ENVIRONMENT=production
npm run build
# Build a Docker image for the server application
- name: Build Docker Image
# Build image with tag thiendang/devops-training-mern-docker-github-actions-cicd:api
run: |
docker build -t thiendang/devops-training-mern-docker-github-actions-cicd:webapp-${{github.run_number}} -t thiendang/devops-training-mern-docker-github-actions-cicd:webapp-latest .
# Log in to Docker Hub using credentials from repository secrets
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Push the Docker images to Docker Hub
- name: Push Docker Images to Docker Hub
run: |
docker push thiendang/devops-training-mern-docker-github-actions-cicd:webapp-${{github.run_number}}
docker push thiendang/devops-training-mern-docker-github-actions-cicd:webapp-latest
# This is the step that is deploying the application to Elastic Beanstalk.
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.EB_APP_NAME }}
environment_name: ${{ secrets.EB_ENV_NAME }}
region: ${{ secrets.EB_REGION }}
version_label: "version-${{ github.run_number }}"
deployment_package: docker-compose.yaml