diff --git a/.dockerignore b/.dockerignore index 52a79f5..2b5059d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,4 +6,5 @@ README.md .next !.next/static !.next/standalone -.git \ No newline at end of file +.git +.env \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6bca06f..5348e17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,13 +39,15 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Set up Environment + run: | + echo "SPOTIFY_CLIENT_ID=${{ secrets.SPOTIFY_CLIENT_ID }}" >> $GITHUB_ENV + echo "SPOTIFY_CLIENT_SECRET=${{ secrets.SPOTIFY_CLIENT_SECRET }}" >> $GITHUB_ENV + echo "GH_TOKEN=${{ secrets.GH_TOKEN }}" >> $GITHUB_ENV + - name: Build and push uses: docker/build-push-action@v6 with: - secrets: | - "SPOTIFY_CLIENT_ID=${{ secrets.SPOTIFY_CLIENT_ID }}" - "SPOTIFY_CLIENT_SECRET=${{ secrets.SPOTIFY_CLIENT_SECRET }}" - "GH_TOKEN=${{ secrets.GH_TOKEN }}" push: true tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha @@ -56,19 +58,20 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - deploy: - needs: build - runs-on: ubuntu-latest - steps: - - name: Deploy to server - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_SSH_KEY }} - port: ${{ secrets.SERVER_PORT }} - script: | - docker-compose down links - docker-compose pull - docker-compose up links -d + # deploy: + # needs: build + # runs-on: ubuntu-latest + # steps: + # - name: Deploy to server + # uses: appleboy/ssh-action@v1.0.3 + # with: + # host: ${{ secrets.SERVER_HOST }} + # username: ${{ secrets.SERVER_USERNAME }} + # password: ${{ secrets.SERVER_PASSWORD }} + # key: ${{ secrets.SERVER_SSH_KEY }} + # port: ${{ secrets.SERVER_PORT }} + # script: | + # docker-compose down links + # docker-compose pull + # docker-compose up links -d diff --git a/Dockerfile b/Dockerfile index d2ccdf2..5e71047 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,55 @@ FROM node:18-alpine AS base -FROM base AS deps -RUN apk add --no-cache libc6-compat +FROM base AS builder + WORKDIR /app COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ elif [ -f package-lock.json ]; then npm ci; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ - else echo "Lockfile not found." && exit 1; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \ + else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ fi - -FROM base AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN --mount=type=secret,id=SPOTIFY_CLIENT_ID \ - --mount=type=secret,id=SPOTIFY_CLIENT_SECRET \ - --mount=type=secret,id=GH_TOKEN \ - export SPOTIFY_CLIENT_ID=$(cat /run/secrets/SPOTIFY_CLIENT_ID) &&\ - export SPOTIFY_CLIENT_SECRET=$(cat /run/secrets/SPOTIFY_CLIENT_ID) &&\ - export GH_TOKEN=$(cat /run/secrets/SPOTIFY_CLIENT_ID) && \ - corepack enable pnpm &&\ - pnpm run build +ARG SPOTIFY_CLIENT_ID +ARG SPOTIFY_CLIENT_SECRET +ARG GH_TOKEN +ENV SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID} +ENV SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET} +ENV GH_TOKEN=${GH_TOKEN} + +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN \ + if [ -f yarn.lock ]; then yarn build; \ + elif [ -f package-lock.json ]; then npm run build; \ + elif [ -f pnpm-lock.yaml ]; then pnpm build; \ + else npm run build; \ + fi FROM base AS runner -WORKDIR /app -ENV NODE_ENV=production +WORKDIR /app RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +USER nextjs COPY --from=builder /app/public ./public - -RUN mkdir .next -RUN chown nextjs:nodejs .next - COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -USER nextjs -EXPOSE 3000 -ENV PORT=3000 -ENV HOSTNAME="0.0.0.0" +ARG SPOTIFY_CLIENT_ID +ARG SPOTIFY_CLIENT_SECRET +ARG GH_TOKEN +ENV SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID} +ENV SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET} +ENV GH_TOKEN=${GH_TOKEN} + +ENV NEXT_TELEMETRY_DISABLED 1 CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml index 2ab5349..68772b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,12 @@ name: "links" services: links: image: "links" - build: . + build: + context: . + dockerfile: Dockerfile + args: + SPOTIFY_CLIENT_ID: ${SPOTIFY_CLIENT_ID} + SPOTIFY_CLIENT_SECRET: ${SPOTIFY_CLIENT_SECRET} + GH_TOKEN: ${GH_TOKEN} ports: - "3000:3000" - environment: - - SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID} - - SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET} - - GH_TOKEN=${GH_TOKEN}