diff --git a/.github/workflows/web-container.yml b/.github/workflows/web-container.yml new file mode 100644 index 0000000..5e58904 --- /dev/null +++ b/.github/workflows/web-container.yml @@ -0,0 +1,101 @@ +name: Web Deployment Container +on: + workflow_dispatch: {} + pull_request: + branches: + - main + types: + - opened + - reopened + - synchronize + - ready_for_review + paths: + - web/** + push: + branches: + - main + paths: + - web/** +jobs: + determine-workflow: + runs-on: 'ubuntu-latest' + outputs: + workflow_type: ${{ steps.workflow.outputs.workflow_type }} + workflow_envs: ${{ steps.workflow.outputs.workflow_envs }} + release_type: ${{ steps.workflow.outputs.release_type }} + current_version: ${{ steps.version.outputs.current_version }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Determine Workflow + id: workflow + shell: bash + run: | + event=${{ github.event_name }} + workflow_type='dev'; + workflow_envs='["dev"]' + if [[ $event == 'workflow_dispatch' && '${{ github.ref_name }}' == 'main' ]]; + then + echo "in if statement" + workflow_type='release'; + workflow_envs='["prod"]' + fi + + echo "workflow_type=$workflow_type" >> $GITHUB_OUTPUT + echo "workflow_envs=$workflow_envs" >> $GITHUB_OUTPUT + + echo "Running $workflow_type pipeline in environments: $workflow_envs" >> $GITHUB_STEP_SUMMARY + - name: Extract Version + id: version + shell: bash + run: | + version=$(jq -r '.version' web/package.json) + echo "current_version=$version" >> "$GITHUB_OUTPUT" + nonprod-deploy: + needs: determine-workflow + if: needs.determine-workflow.outputs.workflow_type != 'release' + strategy: + max-parallel: 1 + matrix: + env: ${{ fromJson(needs.determine-workflow.outputs.workflow_envs) }} + uses: ./.github/workflows/web-deploy-nonprod.yml + with: + environments: ${{ matrix.env }} + workflow_type: ${{ needs.determine-workflow.outputs.workflow_type }} + branch: ${{ github.head_ref || github.ref_name }} + current_version: ${{ needs.determine-workflow.outputs.current_version }} + secrets: + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + TEST: ${{ secrets.TEST }} + # TEAMCITY_WEB_ID: ${{ secrets.TEAMCITY_WEB_ID }} + # TEAMCITY_URL: ${{ secrets.TEAMCITY_URL }} + # TEAMCITY_USERNAME: ${{ secrets.TEAMCITY_USERNAME }} + # TEAMCITY_PASSWORD: ${{ secrets.TEAMCITY_PASSWORD }} + permissions: + contents: read + packages: write + prod-deploy: + needs: determine-workflow + if: needs.determine-workflow.outputs.workflow_type == 'release' + strategy: + max-parallel: 1 + matrix: + env: ${{ fromJson(needs.determine-workflow.outputs.workflow_envs) }} + uses: ./.github/workflows/web-deploy-prod.yml + with: + environments: ${{ matrix.env }} + workflow_type: ${{ needs.determine-workflow.outputs.workflow_type }} + branch: ${{ github.head_ref || github.ref_name }} + current_version: ${{ needs.determine-workflow.outputs.current_version }} + secrets: + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + TEST: ${{ secrets.TEST }} + # TEAMCITY_WEB_ID: ${{ secrets.TEAMCITY_WEB_ID }} + # TEAMCITY_URL: ${{ secrets.TEAMCITY_URL }} + # TEAMCITY_USERNAME: ${{ secrets.TEAMCITY_USERNAME }} + # TEAMCITY_PASSWORD: ${{ secrets.TEAMCITY_PASSWORD }} + permissions: + contents: read + packages: write diff --git a/.github/workflows/web-deploy-nonprod.yml b/.github/workflows/web-deploy-nonprod.yml new file mode 100644 index 0000000..3841e2a --- /dev/null +++ b/.github/workflows/web-deploy-nonprod.yml @@ -0,0 +1,111 @@ +name: Web Deployment Non-Production +on: + workflow_call: + inputs: + environments: + type: string + description: An optional list of environments to deploy to. + default: 'dev' + workflow_type: + type: string + description: An optional string for workflow types. + default: 'dev' + branch: + type: string + description: An optional string to define which branch to checkout. + default: 'main' + current_version: + type: string + description: Current Version of the package.json. + default: '0.0.0' + secrets: + DOCKERHUB_USER: {} + DOCKERHUB_TOKEN: {} + TEST: {} + TEAMCITY_WEB_ID: {} + TEAMCITY_URL: {} + TEAMCITY_USERNAME: {} + TEAMCITY_PASSWORD: {} +jobs: + check-inputs: + runs-on: 'ubuntu-latest' + environment: ${{ inputs.environments }} + steps: + - name: Check secrets present + run: | + if [[ -z "${{ secrets.TEAMCITY_WEB_ID }}" ]]; then + echo "TEAMCITY_WEB_ID secret is empty or missing" + exit 1 + else + echo "TEAMCITY_WEB_ID secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_URL }}" ]]; then + echo "TEAMCITY_URL secret is empty or missing" + exit 1 + else + echo "TEAMCITY_URL secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_USERNAME }}" ]]; then + echo "TEAMCITY_USERNAME secret is empty or missing" + exit 1 + else + echo "TEAMCITY_USERNAME secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_PASSWORD }}" ]]; then + echo "TEAMCITY_PASSWORD secret is empty or missing" + exit 1 + else + echo "TEAMCITY_PASSWORD secret is set" + fi + if [[ -z "${{ secrets.DOCKERHUB_USER }}" ]]; then + echo "DOCKERHUB_USER secret is empty or missing" + exit 1 + else + echo "DOCKERHUB_USER secret is set" + fi + if [[ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then + echo "DOCKERHUB_TOKEN secret is empty or missing" + exit 1 + else + echo "DOCKERHUB_TOKEN secret is set" + fi + echo "Current Version: ${{inputs.current_version}}" + build: + needs: check-inputs + if: needs.check-inputs.result == 'success' && inputs.workflow_type != 'release' + environment: ${{ inputs.environments }} + runs-on: 'ubuntu-latest' + permissions: + contents: read + packages: write + steps: + - name: Branch Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + - name: Login to Docker + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker Build Backend + run: docker build -f web/Dockerfile -t john4064/matchmaking:latest_web ./web --build-arg ENVIRONMENT=dev + - name: Docker Push Backend + run: docker push john4064/matchmaking:latest_web + # deploy: + # needs: build + # if: needs.build.result == 'success' && inputs.workflow_type != 'release' + # environment: ${{ inputs.environments }} + # runs-on: 'ubuntu-latest' + # permissions: + # contents: read + # packages: write + # steps: + # - name: Deploy to Team City + # run: | + # curl -u ${{ secrets.TEAMCITY_USERNAME }}:${{ secrets.TEAMCITY_PASSWORD }} \ + # -X POST \ + # -H "Content-Type: application/json" \ + # -d '{"buildType": {"id": "${{ secrets.TEAMCITY_WEB_ID }}"}}' \ + # "${{ secrets.TEAMCITY_URL }}/httpAuth/app/rest/buildQueue" > /dev/null \ No newline at end of file diff --git a/.github/workflows/web-deploy-prod.yml b/.github/workflows/web-deploy-prod.yml new file mode 100644 index 0000000..2265cf3 --- /dev/null +++ b/.github/workflows/web-deploy-prod.yml @@ -0,0 +1,111 @@ +name: Web Deployment Production +on: + workflow_call: + inputs: + environments: + type: string + description: An optional list of environments to deploy to. + default: 'prod' + workflow_type: + type: string + description: An optional string for workflow types. + default: 'prod' + branch: + type: string + description: An optional string to define which branch to checkout. + default: 'main' + current_version: + type: string + description: Current Version of the package.json. + default: '0.0.0' + secrets: + DOCKERHUB_USER: {} + DOCKERHUB_TOKEN: {} + TEST: {} + TEAMCITY_WEB_ID: {} + TEAMCITY_URL: {} + TEAMCITY_USERNAME: {} + TEAMCITY_PASSWORD: {} +jobs: + check-inputs: + runs-on: 'ubuntu-latest' + environment: ${{ inputs.environments }} + steps: + - name: Check secrets present + run: | + if [[ -z "${{ secrets.TEAMCITY_WEB_ID }}" ]]; then + echo "TEAMCITY_WEB_ID secret is empty or missing" + exit 1 + else + echo "TEAMCITY_WEB_ID secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_URL }}" ]]; then + echo "TEAMCITY_URL secret is empty or missing" + exit 1 + else + echo "TEAMCITY_URL secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_USERNAME }}" ]]; then + echo "TEAMCITY_USERNAME secret is empty or missing" + exit 1 + else + echo "TEAMCITY_USERNAME secret is set" + fi + if [[ -z "${{ secrets.TEAMCITY_PASSWORD }}" ]]; then + echo "TEAMCITY_PASSWORD secret is empty or missing" + exit 1 + else + echo "TEAMCITY_PASSWORD secret is set" + fi + if [[ -z "${{ secrets.DOCKERHUB_USER }}" ]]; then + echo "DOCKERHUB_USER secret is empty or missing" + exit 1 + else + echo "DOCKERHUB_USER secret is set" + fi + if [[ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then + echo "DOCKERHUB_TOKEN secret is empty or missing" + exit 1 + else + echo "DOCKERHUB_TOKEN secret is set" + fi + echo "Current Version: ${{inputs.current_version}}" + build: + needs: check-inputs + if: needs.check-inputs.result == 'success' && inputs.workflow_type == 'release' + environment: ${{ inputs.environments }} + runs-on: 'ubuntu-latest' + permissions: + contents: read + packages: write + steps: + - name: Branch Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + - name: Login to Docker + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker Build Backend + run: docker build -f web/Dockerfile -t john4064/matchmaking:prod_web ./web --build-arg ENVIRONMENT=prod + - name: Docker Push Backend + run: docker push john4064/matchmaking:prod_web + # deploy: + # needs: build + # if: needs.build.result == 'success' && inputs.workflow_type == 'release' + # environment: ${{ inputs.environments }} + # runs-on: 'ubuntu-latest' + # permissions: + # contents: read + # packages: write + # steps: + # - name: Deploy to Team City + # run: | + # curl -u ${{ secrets.TEAMCITY_USERNAME }}:${{ secrets.TEAMCITY_PASSWORD }} \ + # -X POST \ + # -H "Content-Type: application/json" \ + # -d '{"buildType": {"id": "${{ secrets.TEAMCITY_WEB_ID }}"}}' \ + # "${{ secrets.TEAMCITY_URL }}/httpAuth/app/rest/buildQueue" > /dev/null \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e785e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:20-alpine + +WORKDIR /app + +COPY ./package*.json ./ + +RUN npm ci + +COPY . ./ + +EXPOSE 5173 + +ARG ENVIRONMENT +ENV ENVIRONMENT ${ENVIRONMENT} + +CMD npm run prod \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4f3c528..dd87edf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3100,24 +3100,6 @@ "dev": true, "license": "ISC" }, - "node_modules/yaml": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz", - "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==", - "dev": true, - "license": "ISC", - "optional": true, - "peer": true, - "bin": { - "yaml": "bin.mjs" - }, - "engines": { - "node": ">= 14.6" - }, - "funding": { - "url": "https://github.com/sponsors/eemeli" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index dd78818..3dd5f48 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "version": "0.0.1", "type": "module", "scripts": { - "dev": "vite", + "local": "vite", + "dev": "vite --host --mode dev", + "prod": "vite --host --mode prod", "build": "vite build", "lint": "eslint .", "preview": "vite preview"