-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dominikszewczyk/feature/cicd
Creatng CICD for Dev and Prod env
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: CI/CD - Development | ||
|
||
on: | ||
push: | ||
branches: | ||
- feature/** | ||
- bugfix/** | ||
- hotfix/** | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get branch name | ||
id: get_branch | ||
run: | | ||
branch_name=$(echo "${GITHUB_REF#refs/heads/}" | sed 's/\//-/g') | ||
echo "branch_name=$branch_name" >> $GITHUB_ENV | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build app | ||
run: BRANCH_NAME=$branch_name npm run build | ||
|
||
- name: Install SSH Key | ||
uses: shimataro/ssh-key-action@v2 | ||
with: | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
known_hosts: 'just-a-placeholder-so-we-dont-get-errors' | ||
|
||
- name: List SSH directory | ||
run: ls -l ~/.ssh | ||
|
||
- name: Deploy to Dev Server | ||
run: | | ||
mkdir -p ~/.ssh | ||
chmod 700 ~/.ssh | ||
touch ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
echo "${{ secrets.SSH_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa | ||
ssh-keyscan -p ${{ secrets.HOSTING_SSH_PORT }} "${{ secrets.HOSTING_URL }}" >> ~/.ssh/known_hosts | ||
rsync -avz --delete -e "ssh -p ${{ secrets.HOSTING_SSH_PORT }}" dist/ ${{ secrets.HOSTING_SSH_USER }}:${{ secrets.DEPLOY_PATH }}-dev/${{ env.branch_name }} | ||
env: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: CI/CD - Production | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build app | ||
run: npm run build | ||
|
||
- name: Install SSH Key | ||
uses: shimataro/ssh-key-action@v2 | ||
with: | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
known_hosts: 'just-a-placeholder-so-we-dont-get-errors' | ||
|
||
- name: List SSH directory | ||
run: ls -l ~/.ssh | ||
|
||
- name: Deploy to Prod Server | ||
run: | | ||
mkdir -p ~/.ssh | ||
chmod 700 ~/.ssh | ||
touch ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
echo "${{ secrets.SSH_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa | ||
ssh-keyscan -p ${{ secrets.HOSTING_SSH_PORT }} "${{ secrets.HOSTING_URL }}" >> ~/.ssh/known_hosts | ||
rsync -avz --delete -e "ssh -p ${{ secrets.HOSTING_SSH_PORT }}" dist/ ${{ secrets.HOSTING_SSH_USER }}:${{ secrets.DEPLOY_PATH }} | ||
env: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- name: Generate unique tag based on date and time | ||
id: tag | ||
run: | | ||
new_tag=$(date +"%Y%m%d-%H%M") | ||
echo "New tag: $new_tag" | ||
echo "TAG=$new_tag" >> $GITHUB_ENV | ||
- name: Create and push new tag | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{ env.TAG }} | ||
release_name: false | ||
draft: false | ||
prerelease: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.CICD_DEV_TOKEN }} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.github/workflows/secret.txt |
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