feat: deloyment completed #4
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
# 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: | | |
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: | | |
npm install | |
npm run build | |
export MONGODB_URI=$MONGODB_URI | |
# Build a Docker image for the client application | |
- name: Build Client Docker Image | |
working-directory: ./ui | |
# Build image with tag thiendang/devops-training-mern-docker-github-actions-cicd:client | |
run: | | |
docker build -t thiendang/devops-training-mern-docker-github-actions-cicd:ui-${{github.run_number}} -t thiendang/devops-training-mern-docker-github-actions-cicd:ui-latest . | |
# Build a Docker image for the server application | |
- name: Build Server Docker Image | |
working-directory: | |
./api | |
# 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:api-${{github.run_number}} -t thiendang/devops-training-mern-docker-github-actions-cicd:api-latest . | |
# Build a Docker image for the NGINX reverse proxy | |
# - name: Build NGINX Docker Image | |
# working-directory: ./nginx | |
# # Build image with tag thiendang/devops-training-mern-docker-github-actions-cicd:nginx | |
# run: | | |
# docker build -t thiendang/devops-training-mern-docker-github-actions-cicd:nginx-${{github.run_number}} -t thiendang/devops-training-mern-docker-github-actions-cicd:nginx-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:ui-${{github.run_number}} | |
docker push thiendang/devops-training-mern-docker-github-actions-cicd:api-${{github.run_number}} | |
# 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.yml |