-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release' of https://github.com/peer-42seoul/Peer-Frontend…
… into release-1.0.2
- Loading branch information
Showing
1 changed file
with
105 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,105 @@ | ||
name: Main CI/CD | ||
|
||
on: | ||
pull_request: | ||
branches: ['env/main_cicd'] | ||
types: ['closed'] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
check-branch: | ||
if: contains(github.head_ref, 'release') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check branch | ||
run: | | ||
echo "This is a release branch" | ||
check-merged: | ||
needs: check-branch | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check merged | ||
run: | | ||
echo "This is a merged release branch" | ||
extract-version: | ||
needs: check-merged | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.extract-version.outputs.version }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Extract version | ||
id: extract-version | ||
run: | | ||
echo "Extract version: this version is $(echo "$(git show -s --format=%s)" | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')" >> "$GITHUB_OUTPUT" | ||
CI: | ||
name: Main Server CI Check | ||
needs: extract-version | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
- name: Check version | ||
run: | | ||
echo "This release version: ${{ needs.extract-version.outputs.version }}" | ||
- name: Install Docker | ||
run: docker compose up -d | ||
- name: Change directory | ||
run: cd ${{ secrets.WORK_DIRECTORY }} // 환경 변수화 필요 | ||
- name: Install dependencies | ||
run: npm install ${{ secrets.WORK_DIRECTORY }} | ||
- name: Prettier | ||
run: npm run prettier | ||
- name: Lint | ||
run: npm run lint | ||
- name: Build Test | ||
run: npm run build | ||
|
||
CD: | ||
name: Main Server CD Check | ||
needs: CI | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
run: | | ||
touch ${{ secrets.WORK_DIRECTORY }}/.env.production | ||
echo "${{ secrets.MAIN_ENV }}" >> /home/runner/work/Peer-Frontend/Peer-Frontend/.env.production | ||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }} . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }} | ||
- name: Deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.MAIN_HOST }} | ||
port: 4222 | ||
username: ${{ secrets.MAIN_USERNAME }} | ||
key: ${{ secrets.MAIN_KEY }} | ||
script: | | ||
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }} | ||
docker rm -f ${{ secrets.MAIN_DOCKER_IMAGE }} | ||
docker run -d -p 3000:3000 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }} | ||
docker container prune -f | ||
docker image prune -f |