diff --git a/.github/workflows/api-dotnetcore.yml b/.github/workflows/api-dotnetcore.yml deleted file mode 100644 index 3a950299..00000000 --- a/.github/workflows/api-dotnetcore.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: API (.NET Core) - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - build: - runs-on: ubuntu-latest - env: - working-directory: ./api - - steps: - - uses: actions/checkout@v4 - - name: Setup .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 5.x - - name: Install dependencies - run: dotnet restore - working-directory: ${{env.working-directory}} - - name: Build - run: dotnet build --configuration Release --no-restore - working-directory: ${{env.working-directory}} - - name: Test - run: dotnet test --no-restore --verbosity normal - working-directory: ${{env.working-directory}} diff --git a/.github/workflows/api.yaml b/.github/workflows/api.yaml new file mode 100644 index 00000000..52f88d96 --- /dev/null +++ b/.github/workflows/api.yaml @@ -0,0 +1,72 @@ +name: API + +on: + workflow_dispatch: +env: + IMAGE_NAME: api + WORKING_DIRECTORY: ./ +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Login to Artifactory + uses: docker/login-action@v1 + with: + registry: artifacts.developer.gov.bc.ca + username: ${{ secrets.ARTIFACTORY_USERNAME }} + password: ${{ secrets.ARTIFACTORY_PASSWORD }} + + # Get SHORT_SHA to tag images + - name: Get short SHA + id: short_sha + run: | + echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)" + echo "Short SHA: $SHORT_SHA" + + - name: Docker Build Image + run: | + docker build --tag ${{ env.IMAGE_NAME }} -f api/Dockerfile . + docker tag ${{ env.IMAGE_NAME }} artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:dev-${{ steps.short_sha.outputs.SHORT_SHA }} + docker push artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:dev-${{ steps.short_sha.outputs.SHORT_SHA }} + + - name: Checkout ArgoCD Repo + id: gitops + uses: actions/checkout@v4 + with: + repository: bcgov-c/tenant-gitops-cb6495 + ref: develop + token: ${{ secrets.GIT_OPS_SSH_KEY }} # `GH_PAT` is a secret that contains your PAT + path: gitops + + - name: Update Helm Values and Commit + id: helm + if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful + run: | + # Clone the GitOps deployment configuration repository + # Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and + cd gitops/charts + + # Update the Helm values file with the new image tag and version + DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time + + sed -i "s/apitag: .*/apitag: dev-${{ steps.short_sha.outputs.SHORT_SHA }} # Image Updated on $DATETIME/" ../deploy/dev_values.yaml + + sed -i "s/apitag: .*/apitag: dev-${{ steps.short_sha.outputs.SHORT_SHA }} # Image Updated on $DATETIME/" api/values.yaml + + # Commit and push the changes + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + + git add . + + git add ../deploy/dev_values.yaml + + git commit -m "Update API image tag" + git push origin develop # Update the branch name as needed + + diff --git a/.github/workflows/app-vue.yml b/.github/workflows/app-vue.yml deleted file mode 100644 index cd9975c2..00000000 --- a/.github/workflows/app-vue.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: APP (Vue) - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - build: - runs-on: ubuntu-latest - env: - CI: true - working-directory: ./web - codeCov-token: ${{ secrets.CodeCov }} - - strategy: - matrix: - node-version: [10.x] - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - run: npm install && npm ci - working-directory: ${{env.working-directory}} - - run: npm run build --if-present - working-directory: ${{env.working-directory}} diff --git a/.github/workflows/backup.yaml b/.github/workflows/backup.yaml new file mode 100644 index 00000000..2589724c --- /dev/null +++ b/.github/workflows/backup.yaml @@ -0,0 +1,35 @@ +name: Backup + +on: + workflow_dispatch: +env: + IMAGE_NAME: backup + WORKING_DIRECTORY: ./ +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - name: Login to Artifactory + uses: docker/login-action@v1 + with: + registry: artifacts.developer.gov.bc.ca + username: ${{ secrets.ARTIFACTORY_USERNAME }} + password: ${{ secrets.ARTIFACTORY_PASSWORD }} + + - name: Checkout Backup Container Repo + id: gitops + uses: actions/checkout@v4 + with: + repository: BCDevOps/backup-container.git + ref: 2.9.0 + + - name: Docker Build Backup Image + run: | + cd docker + docker build --tag ${{ env.IMAGE_NAME }} . + docker tag ${{ env.IMAGE_NAME }} artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:latest + docker push artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }} + + diff --git a/.github/workflows/schema-spy.yaml b/.github/workflows/schema-spy.yaml new file mode 100644 index 00000000..098eb2c8 --- /dev/null +++ b/.github/workflows/schema-spy.yaml @@ -0,0 +1,34 @@ +name: Schema-Spy + +on: + workflow_dispatch: +env: + IMAGE_NAME: schema-spy + WORKING_DIRECTORY: ./ +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - name: Login to Artifactory + uses: docker/login-action@v1 + with: + registry: artifacts.developer.gov.bc.ca + username: ${{ secrets.ARTIFACTORY_USERNAME }} + password: ${{ secrets.ARTIFACTORY_PASSWORD }} + + - name: Checkout Schema Spy Repo + id: gitops + uses: actions/checkout@v4 + with: + repository: bcgov/SchemaSpy.git + ref: master + + - name: Docker Build Schema Spy Image + run: | + docker build --tag ${{ env.IMAGE_NAME }} . + docker tag ${{ env.IMAGE_NAME }} artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:latest + docker push artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }} + + diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml new file mode 100644 index 00000000..75683187 --- /dev/null +++ b/.github/workflows/web.yml @@ -0,0 +1,72 @@ +name: Web + +on: + workflow_dispatch: +env: + IMAGE_NAME: web + WORKING_DIRECTORY: ./ +jobs: + builds: + runs-on: ubuntu-latest + + steps: + - name: Login to Artifactory + uses: docker/login-action@v1 + with: + registry: artifacts.developer.gov.bc.ca + username: ${{ secrets.ARTIFACTORY_USERNAME }} + password: ${{ secrets.ARTIFACTORY_PASSWORD }} + + - name: Checkout Repo + uses: actions/checkout@v4 + + # Get SHORT_SHA to tag images + - name: Get short SHA + id: short_sha + run: | + echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)" + echo "Short SHA: $SHORT_SHA" + + - name: Docker Build Image + run: | + docker build --tag nginx-runtime -f docker/nginx-runtime/Dockerfile ./docker/nginx-runtime/ + cd web + docker build --tag ss-web-artifacts -f Dockerfile.node . --build-arg WEB_BASE_HREF=${{ vars.WEB_BASE_HREF }} + cd .. + docker build --tag ${{ env.IMAGE_NAME }} -f docker/vue-on-nginx/Dockerfile ./docker/vue-on-nginx/ + docker tag ${{ env.IMAGE_NAME }} artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:dev-${{ steps.short_sha.outputs.SHORT_SHA }} + docker push artifacts.developer.gov.bc.ca/ccb6-images/${{ env.IMAGE_NAME }}:dev-${{ steps.short_sha.outputs.SHORT_SHA }} + + - name: Checkout ArgoCD Repo + id: gitops + uses: actions/checkout@v4 + with: + repository: bcgov-c/tenant-gitops-cb6495 + ref: develop + token: ${{ secrets.GIT_OPS_SSH_KEY }} # `GH_PAT` is a secret that contains your PAT + path: gitops + + - name: Update Helm Values and Commit + id: helm + if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful + run: | + # Clone the GitOps deployment configuration repository + # Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and + cd gitops/charts + + # Update the Helm values file with the new image tag and version + DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time + + sed -i "s/webtag: .*/webtag: dev-${{ steps.short_sha.outputs.SHORT_SHA }} # Image Updated on $DATETIME/" ../deploy/dev_values.yaml + + sed -i "s/webtag: .*/webtag: dev-${{ steps.short_sha.outputs.SHORT_SHA }} # Image Updated on $DATETIME/" web/values.yaml + + # Commit and push the changes + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + + git add . + + git add ../deploy/dev_values.yaml + git commit -m "Update Dev Web image tag" + git push origin develop # Update the branch name as needed diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..99c154c5 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,30 @@ +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base +WORKDIR /app +EXPOSE 8080 +ENV ASPNETCORE_URLS=http://*:8080 +ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true +ENV DOTNET_gcServer=1 +ARG VERSION +ENV VERSION=$VERSION + +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build + +WORKDIR /src + +COPY ["api/api.csproj", "api/"] +COPY ["db/db.csproj", "db/"] +RUN dotnet restore api/api.csproj +RUN dotnet restore db/db.csproj +COPY . . +RUN dotnet build "api/api.csproj" -c Release +# build +FROM build AS publish +RUN dotnet publish "api/api.csproj" -c Release -o /app/publish --runtime linux-musl-x64 --no-self-contained + +FROM base AS final + +# copy app +WORKDIR /app +COPY --from=publish /app/publish . +COPY --from=build /src/db/sql /src/db/sql +ENTRYPOINT ["dotnet", "api.dll"] diff --git a/web/Dockerfile.node b/web/Dockerfile.node new file mode 100644 index 00000000..3390f3b1 --- /dev/null +++ b/web/Dockerfile.node @@ -0,0 +1,10 @@ +FROM centos/nodejs-10-centos7:10 +ARG WEB_BASE_HREF +ENV WEB_BASE_HREF="$WEB_BASE_HREF" +ENV WEB1_BASE_HREF="$WEB_BASE_HREF" +WORKDIR /opt/app-root/src +COPY . . +RUN echo "$WEB1_BASE_HREF" +RUN echo "$WEB_BASE_HREF" +RUN npm install +RUN npm run build