From a9ecb94f8098e813f96607d091c50f6a39105afe Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Sun, 30 Jun 2024 10:21:17 +0100 Subject: [PATCH] feat: release + docker container (#136) * feat: Dockerfile * fix: .dockerignore * feat: create release * feat: push to ghcr --- .dockerignore | 33 +++++++++++++++++++ .github/workflows/docker.yml | 44 +++++++++++++++++++++++++ .github/workflows/release.yml | 60 +++++++++++++++++++++++++++++++++++ Dockerfile | 14 ++++++++ 4 files changed, 151 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..16012bb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,33 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..b40d320 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,44 @@ +name: Publish Docker image +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: npm install and build + run: | + npm ci + npm run build + - uses: actions/upload-artifact@main + with: + name: artifacts + path: prod/ + push_to_registry: + name: Push Docker image to GitHub Packages + needs: build + runs-on: ubuntu-latest + steps: + - name: check out the repo + uses: actions/checkout@v4 + - name: get-npm-version + id: package-version + uses: martinbeentjes/npm-get-version-action@master + - name: version dockerfile + uses: docker/setup-buildx-action@v3 + - name: log into GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + - name: push to Github Container Registry + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ghcr.io/eddiehubcommunity/reporater:v${{ steps.package-version.outputs.current-version}} + ghcr.io/eddiehubcommunity/reporater:latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..89c6a33 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Release +on: + push: + branches: + - main + +jobs: + changelog: + if: github.repository == 'EddieHubCommunity/RepoRater' + runs-on: ubuntu-latest + + steps: + # check out the repository with all releases + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Create a temporary, uniquely named branch to push release info to + - name: create temporary branch + run: git branch "release-from-${{ github.sha }}" "${{ github.sha }}" + + # switch to the temporary branch + - name: switch to new branch + run: git checkout release-from-${{ github.sha }} + + # create release info and push it upstream + - name: conventional Changelog Action + id: changelog + uses: TriPSs/conventional-changelog-action@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + version-file: "./package.json,./package-lock.json,./src/config/app.json" + git-branch: "release-from-${{ github.sha }}" + skip-git-pull: true + + # create PR using GitHub CLI + - name: create PR with release info + if: steps.changelog.outputs.skipped == 'false' + id: create-pr + run: gh pr create --base main --head release-from-${{ github.sha }} --title 'Merge new release into main' --body 'Created by Github action' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # merge PR using GitHub CLI + - name: merge PR with release info + if: steps.changelog.outputs.skipped == 'false' + id: merge-pr + run: gh pr merge --admin --merge --subject 'Merge release info' --delete-branch + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # release info is now in main so we can continue as before + - name: create release with last commit + if: steps.changelog.outputs.skipped == 'false' + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.CHANGELOG_RELEASE }} + tag: ${{ steps.changelog.outputs.tag }} + name: ${{ steps.changelog.outputs.tag }} + body: ${{ steps.changelog.outputs.clean_changelog }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9c39957 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +ARG NODE_VERSION=20 + +FROM node:${NODE_VERSION} +LABEL org.opencontainers.image.source https://github.com/eddiehubcommunity/RepoRater + +WORKDIR /usr/src/app + +COPY . . + +RUN npm ci + +EXPOSE 3000 + +CMD npm run build && npm start