diff --git a/.env b/.env deleted file mode 100644 index 973d45e0..00000000 --- a/.env +++ /dev/null @@ -1,7 +0,0 @@ -APPLICATION_ENV="develop" -SERVER_ADDRESS="0.0.0.0" -SERVER_PORT="3000" -DATABASE_HOST="nutfes-seeft-db" -DATABASE_USER="seeft" -DATABASE_PASSWORD="password" -DATABASE_NAME="seeft_db" \ No newline at end of file diff --git a/.github/workflows/deployment-prod.yml b/.github/workflows/deployment-prod.yml new file mode 100644 index 00000000..51c20cdf --- /dev/null +++ b/.github/workflows/deployment-prod.yml @@ -0,0 +1,37 @@ +name: CD + +on: + workflow_call: + workflow_dispatch: + +jobs: + deploy: + runs-on: self-hosted + steps: + - name: Add deploy host key + run: | + mkdir -p ~/.ssh + ssh-keygen -R "${{ secrets.CONTAINER_IP }}" 2>/dev/null || true + echo "${{ secrets.DEPLOY_HOST_KEY }}" >> ~/.ssh/known_hosts + + - name: SSH and Deploy + env: + HARBOR_PASS: ${{ secrets.HARBOR_PASS }} + HARBOR_REG: ${{ secrets.HARBOR_REG }} + HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} + run: | + ssh deploy-user@${{ secrets.CONTAINER_IP }} -T \ + -o SendEnv=HARBOR_PASS \ + -o SendEnv=HARBOR_REG \ + -o SendEnv=HARBOR_USERNAME \ + bash -s << 'EOF' + set -e + cd /home/deploy-user/SeeFT + git fetch origin feat/mitomen/261/CI-CD-Pipeline + git reset --hard origin/feat/mitomen/261/CI-CD-Pipeline + git checkout -B feat/mitomen/261/CI-CD-Pipeline origin/feat/mitomen/261/CI-CD-Pipeline + echo "$HARBOR_PASS" | docker login "$HARBOR_REG" -u "$HARBOR_USERNAME" --password-stdin + docker compose -f docker-compose.cd.yml pull + docker compose -f docker-compose.cd.yml up -d + docker image prune -f + EOF \ No newline at end of file diff --git a/.github/workflows/integration-prod.yml b/.github/workflows/integration-prod.yml new file mode 100644 index 00000000..0ae6387a --- /dev/null +++ b/.github/workflows/integration-prod.yml @@ -0,0 +1,85 @@ +name: CI + +on: + push: + branches: + - main + - feat/mitomen/261/CI-CD-Pipeline + workflow_call: + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v6 + with: + submodules: recursive + token: ${{ secrets.GH_PAT || github.token }} + + - name: Connect to Tailscale + uses: tailscale/github-action@v2 + with: + oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }} + oauth-secret: ${{ secrets.TAILSCALE_OAUTH_CLIENT_SECRET }} + tags: tag:ci + + - name: Configure Insecure Registry + run: | + sudo service docker stop + echo "{\"insecure-registries\": [\"${{ secrets.HARBOR_REG }}\"]}" | sudo tee /etc/docker/daemon.json + sudo service docker start + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + buildkitd-config-inline: | + [registry."${{ secrets.HARBOR_REG }}"] + http = true + insecure = true + + - name: Log in to Harbor + uses: docker/login-action@v3 + with: + registry: ${{ secrets.HARBOR_REG }} + username: ${{ secrets.HARBOR_USERNAME }} + password: ${{ secrets.HARBOR_PASS }} + + - name: Create .env file + run: | + mkdir -p mobile/env + printf '%s' "${{ secrets.SEEFT_MOBILE_ENVS }}" > mobile/env/.env + + - name: Build and Push API + uses: docker/build-push-action@v5 + with: + context: ./api + file: ./api/prod.Dockerfile + push: true + tags: ${{ secrets.HARBOR_REG }}/seeft/api:latest + cache-from: type=gha + + - name: Build and Push Admin + uses: docker/build-push-action@v5 + with: + context: ./admin + file: ./admin/prod.Dockerfile + push: true + tags: ${{ secrets.HARBOR_REG }}/seeft/admin:latest + cache-from: type=gha + + - name: Build and Push Mobile + uses: docker/build-push-action@v5 + with: + context: ./mobile + file: ./mobile/Dockerfile + push: true + tags: ${{ secrets.HARBOR_REG }}/seeft/mobile:latest + cache-from: type=gha + + trigger-cd: + needs: build-and-push + uses: ./.github/workflows/deployment-prod.yml + secrets: inherit diff --git a/docker-compose.cd.yml b/docker-compose.cd.yml new file mode 100644 index 00000000..af1aa45f --- /dev/null +++ b/docker-compose.cd.yml @@ -0,0 +1,43 @@ +version: "3" +services: + cloudflare: + image: "cloudflare/cloudflared:latest" + container_name: "nutfes-seeft-web" + volumes: ["./web/prod:/home/nonroot/.cloudflared"] + command: tunnel run + + mobile: + image: ${HARBOR_REG}/seeft/mobile:latest + container_name: "nutfes-seeft-mobile" + command: "python3 ./python/server.py" + ports: ["45029:45029"] + environment: + NEXT_PUBLIC_APP_ENV: "production" + depends_on: ["api"] + restart: always + + api: + image: ${HARBOR_REG}/seeft/api:latest + container_name: "nutfes-seeft-api" + volumes: ["./api:/env/app"] + command: sh -c "go build -o main main.go && ./main" + env_file: ["./api/env/seeft.env"] + ports: ["1234:1234"] + restart: always + + admin: + image: ${HARBOR_REG}/seeft/admin:latest + container_name: "nutfes-seeft-admin" + command: sh -c "npm install && npm run build && npm run start" + ports: + - "5000:3000" + environment: + NEXT_PUBLIC_APP_ENV: "production" + stdin_open: true + tty: true + depends_on: [api] + restart: always + +networks: + default: + name: seeft-default \ No newline at end of file