Last active
December 30, 2024 14:03
BE CI Elastic Beanstalk
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: Backend CI | |
on: | |
push: | |
branches: | |
- development | |
- master | |
jobs: | |
backend: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
node: [16.15.0] | |
# env: | |
# NODE_ENV: "development" | |
steps: | |
- name: Checkout 🛎 | |
uses: actions/checkout@v3 | |
- name: Setup node env 🏗 | |
uses: actions/setup-node@v2.1.2 | |
with: | |
node-version: ${{ matrix.node }} | |
# - name: Cache node_modules 📦 | |
# uses: actions/cache@v2 | |
# with: | |
# path: ~/.npm | |
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
# restore-keys: | | |
# ${{ runner.os }}-node- | |
- name: Installing NPM | |
run: | | |
rm -rf package-lock.json | |
rm -rf node_modules | |
npm install | |
- name: Generate deployment package | |
run: zip -r deploy.zip . -x '*.git*' | |
- name: Get timestamp | |
uses: gerred/actions/current-time@master | |
id: current-time | |
- name: Run string replace | |
uses: frabert/replace-string-action@master | |
id: format-time | |
with: | |
pattern: '[:\.]+' | |
string: "${{ steps.current-time.outputs.time }}" | |
replace-with: '-' | |
flags: 'g' | |
- name: Setting env variables for staging | |
run: | | |
echo "ENVIRONMENT_NAME=${{ secrets.STAGING_ENVIRONMENT }}" >> $GITHUB_ENV | |
if: github.ref_name == 'master' | |
- name: Setting env variables for production | |
run: | | |
echo "ENVIRONMENT_NAME=${{ secrets.PROD_ENVIRONMENT }}" >> $GITHUB_ENV | |
if: github.ref_name == 'master' | |
- name: Setting env variables for main/sit | |
run: | | |
echo "ENVIRONMENT_NAME=${{ secrets.SIT_ENVIRONMENT }}" >> $GITHUB_ENV | |
if: github.ref_name == 'development' | |
- name: Beanstalk Deploy for app | |
uses: einaregilsson/beanstalk-deploy@v19 | |
with: | |
aws_access_key: ${{secrets.AWS_ACCESS_KEY_ID}} | |
aws_secret_key: ${{secrets.AWS_SECRET_ACCESS_KEY}} | |
application_name: ${{secrets.APPLICATION_NAME}} | |
environment_name: ${{env.ENVIRONMENT_NAME}} | |
region: ${{ secrets.AWS_REGION }} | |
version_label: "api-${{ steps.format-time.outputs.replaced }}" | |
deployment_package: deploy.zip | |
wait_for_deployment: false | |
wait_for_environment_recovery: 60 | |
- name: Deployed! | |
run: echo App deployed to ELB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment