-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3d0aa8
commit a85c475
Showing
1 changed file
with
74 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,74 @@ | ||
name: API Server Ci/Cd | ||
on: | ||
push: | ||
branches: | ||
- Ci/69 | ||
- develop | ||
paths: | ||
# - 'apps/api/**' | ||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
IMAGE_NAME: api-camon | ||
DB_HOST: ${{ secrets.DB_HOST }} | ||
DB_PORT: ${{ secrets.DB_PORT }} | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to Ncloud Container Registry | ||
env: | ||
USERNAME: ${{ secrets.NCLOUD_ACCESS_KEY }} | ||
PASSWORD: ${{ secrets.NCLOUD_SECRET_KEY }} | ||
REGISTRY_URL: ${{ secrets.NCLOUD_REGISTRY_URL }} | ||
run: | | ||
echo "$PASSWORD" | docker login -u "$USERNAME" "$REGISTRY_URL" --password-stdin | ||
- name: Build Docker image | ||
working-directory: ./apps/api | ||
run: | | ||
docker build -t ${{ secrets.NCLOUD_REGISTRY_URL }}/$IMAGE_NAME:latest \ | ||
--build-arg DB_HOST=$DB_HOST \ | ||
--build-arg DB_PORT=$DB_PORT \ | ||
--build-arg DB_USERNAME=$DB_USERNAME \ | ||
--build-arg DB_PASSWORD=$DB_PASSWORD \ | ||
--build-arg DB_NAME=$DB_NAME \ | ||
. | ||
- name: Push to Ncloud Container Registry | ||
run: | | ||
docker push ${{ secrets.NCLOUD_REGISTRY_URL }}/$IMAGE_NAME:latest | ||
deploy-and-run: | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
steps: | ||
- name: SSH and deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_IP }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_SERVER_KEY }} | ||
port: 22 | ||
script: | | ||
sudo docker login -u ${{secrets.NCLOUD_ACCESS_KEY}} -p ${{ secrets.NCLOUD_SECRET_KEY }} ${{ secrets.NCLOUD_REGISTRY_URL }} | ||
sudo docker pull ${{ secrets.NCLOUD_REGISTRY_URL }}/$IMAGE_NAME:latest | ||
sudo docker stop api-camon || true | ||
sudo docker rm api-camon || true | ||
sudo docker run -d --name api-camon -p 3000:3000 ${{ secrets.NCLOUD_REGISTRY_URL }}/api-camon:latest | ||
- name: Check container status | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_IP }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_SERVER_KEY }} | ||
port: 22 | ||
script: | | ||
sudo docker ps -f name=api-camon |