From cbf48d7b3e4702b106432dbe167fc410a497b2f1 Mon Sep 17 00:00:00 2001 From: DataHearth Date: Mon, 10 Apr 2023 18:21:08 +0200 Subject: [PATCH] add gitea actions --- .dockerignore | 5 ++- .gitea/workflows/deploy.yml | 90 +++++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++---- Justfile | 27 ----------- ecosystem.config.js | 4 +- entrypoint.sh | 2 +- 6 files changed, 108 insertions(+), 41 deletions(-) create mode 100644 .gitea/workflows/deploy.yml delete mode 100644 Justfile diff --git a/.dockerignore b/.dockerignore index 700c9ec..2b938b3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ -Justfile Dockerfile .dockerignore -LICENSE \ No newline at end of file +LICENSE +.gitea +.git \ No newline at end of file diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..87a8310 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,90 @@ +name: deploy + +on: + push: + tags: + - "v*[0-9].*[0-9].*[0-9]?(-rc?(.*[0-9])|-dev?(.*[0-9]))" + - latest + +jobs: + deploy: + # services: + # docker: + # image: docker:dind + # env: + # DOCKER_TLS_CERTDIR: /certs + # options: --privileged + # volumes: + # - /certs/ca:/certs/ca + # - /certs/client:/certs/client + # - /var/run/docker.sock:/var/run/docker.sock + runs-on: ubuntu-latest + container: docker:latest + # env: + # DOCKER_TLS_CERTDIR: /certs + steps: + - name: Set up NodeJS + run: | + apk update + apk add nodejs npm + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Login to Gitea Container Registry + uses: docker/login-action@v2 + with: + registry: gitea.antoine-langlois.net + username: ${{ gitea.repository_owner }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Get latest version + id: get_lts + if: ${{ gitea.ref_name == 'latest' }} + run: | + apk add jq curl + echo "version=$(curl -sfL https://api.github.com/repos/AmruthPillai/Reactive-Resume/releases/latest | jq .tag_name)" >> $GITEA_OUTPUT + + - name: Checkout + # todo: uncomment when checkout support other git servers + # uses: actions/checkout@v3 + run: | + apk add git + git clone --depth 1 --branch ${{ gitea.ref_name }} https://gitea.antoine-langlois.net/${{ gitea.repository }}.git . + + - name: Build and push latest + uses: docker/build-push-action@v4 + if: ${{ gitea.ref_name == 'latest' }} + with: + context: . + platforms: linux/amd64,linux/arm64 + build-args: | + VERSION=${{ steps.get_lts.outputs.version }} + push: true + tags: + datahearth/reactive-resume:${{ steps.get_lts.outputs.version }} + datahearth/reactive-resume:latest + gitea.antoine-langlois.net/reactive-resume:${{ steps.get_lts.outputs.version }} + gitea.antoine-langlois.net/reactive-resume:latest + + - name: Build and push tag + uses: docker/build-push-action@v4 + if: ${{ gitea.ref_name != 'latest' }} + with: + context: . + platforms: linux/amd64,linux/arm64 + build-args: | + VERSION=${{ gitea.ref_name }} + push: true + tags: | + datahearth/reactive-resume:${{ gitea.ref_name } + gitea.antoine-langlois.net/reactive-resume:${{ gitea.ref_name }} diff --git a/Dockerfile b/Dockerfile index 37cd7d8..c4e95ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,22 +2,25 @@ FROM node:lts-bullseye-slim ARG VERSION -RUN apt update -RUN apt install -y git - -RUN git clone --depth 1 --branch ${VERSION} https://github.com/AmruthPillai/Reactive-Resume.git app +RUN apt-get update +RUN apt-get install -y git RUN npm install -g pnpm pm2 +RUN git clone --depth 1 --branch ${VERSION} https://github.com/AmruthPillai/Reactive-Resume.git /app + WORKDIR /app +ENV NEXT_TELEMETRY_DISABLED=1 + RUN pnpm install --frozen-lockfile RUN pnpm build -COPY . . +COPY .env /data/.env.template +COPY entrypoint.sh /data/entrypoint.sh +COPY ecosystem.config.js /data/ecosystem.config.js -RUN cp .env /tmp/.env -RUN mv entrypoint.sh /usr/bin/entrypoint.sh && chmod a+x /usr/bin/entrypoint.sh +RUN chmod a+x /data/entrypoint.sh -ENTRYPOINT [ "/usr/bin/entrypoint.sh" ] -CMD [ "pm2-runtime", "ecosystem.config.js" ] \ No newline at end of file +ENTRYPOINT [ "/data/entrypoint.sh" ] +CMD [ "pm2-runtime", "/data/ecosystem.config.js" ] \ No newline at end of file diff --git a/Justfile b/Justfile deleted file mode 100644 index 0811817..0000000 --- a/Justfile +++ /dev/null @@ -1,27 +0,0 @@ -default: build-latest - -LATEST_VERSION := `xh https://api.github.com/repos/AmruthPillai/Reactive-Resume/releases/latest Accept:application/vnd.github+json X-GitHub-Api-Version:2022-11-28 | jq .tag_name` - -# build and push latest version of reactive-resume to "gitea" and "docker" -build-latest: - @echo "building images..." - docker build -t gitea.antoine-langlois.net/datahearth/reactive-resume:{{LATEST_VERSION}} --build-arg VERSION={{LATEST_VERSION}} . - docker tag gitea.antoine-langlois.net/datahearth/reactive-resume:{{LATEST_VERSION}} gitea.antoine-langlois.net/datahearth/reactive-resume:latest - docker tag gitea.antoine-langlois.net/datahearth/reactive-resume:{{LATEST_VERSION}} datahearth/reactive-resume:{{LATEST_VERSION}} - docker tag gitea.antoine-langlois.net/datahearth/reactive-resume:{{LATEST_VERSION}} datahearth/reactive-resume:latest - - @echo "pushing images..." - docker push gitea.antoine-langlois.net/datahearth/reactive-resume:{{LATEST_VERSION}} - docker push gitea.antoine-langlois.net/datahearth/reactive-resume:latest - docker push datahearth/reactive-resume:{{LATEST_VERSION}} - docker push datahearth/reactive-resume:latest - -# build and push specific version of reactive-resume to "gitea" and "docker" -build VERSION: - @echo "building images..." - docker build -t gitea.antoine-langlois.net/datahearth/reactive-resume:{{VERSION}} --build-arg VERSION={{VERSION}} . - docker tag gitea.antoine-langlois.net/datahearth/reactive-resume:{{VERSION}} datahearth/reactive-resume:{{VERSION}} - - @echo "pushing images..." - docker push gitea.antoine-langlois.net/datahearth/reactive-resume:{{VERSION}} - docker push datahearth/reactive-resume:{{VERSION}} \ No newline at end of file diff --git a/ecosystem.config.js b/ecosystem.config.js index 9a55405..140ac0d 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -1,11 +1,11 @@ module.exports = [ { - script: "pnpm start --filter server", + script: "pnpm --filter server start", cwd: "/app", name: "server", }, { - script: "pnpm start --filter client", + script: "pnpm --filter client start", cwd: "/app", name: "client", }, diff --git a/entrypoint.sh b/entrypoint.sh index 6325d45..e919f7f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if [ ! -f .env ]; then - cp /tmp/.env . + cp /data/.env.template .env fi set -a