0

I was using a CI CD pipeline to deploy my project to the server.
However it suddenly stopped working and I got two errors.

  • The first one is related to git and
  • The second one is a docker error.

Can somebody help me what could be the problem?

32 out: Total reclaimed space: OB
33 err: error: cannot pull with rebase:
You have unstaged changes. err: error: please commit or stash them. 34 35
out: docker build -f Dockerfile . -t
tourmix-next
36 err: time="20***-10-08T11:06:33Z" 
level-error msg="Can't add file 
/mnt/tourmix-main/database/mysql.sock 
to tar: archive/tar: sockets not supported"
37 out: Sending build context to Docker daemon 255MB
38
out: Step 1/21 : FROM node:1ts as
dependencies
39 out: Its: Pulling from library/node
40 out: Digest:
sha256:b35e76ba744a975b9a5428b6c3cde1a1 cf0be53b246e1e9a4874f87034***b5a
47 41 out: Status: Downloaded newer image for node:1ts
2 42 out: ---> 946ee375d0e0
3 4 out: Step 2/21: WORKDIR /tourmix out: ---> Using cache
5 45 out: ---> 05e933ce4fa7

enter image description here

This is my Dockerfile:

1  FROM node:1ts as dependencies
2  WORKDIR /tourmix
3  COPY package*.json ./
4  RUN npm install --force
5
6  FROM node:lts as builder
7  WORKDIR /tourmix
8  COPY . .
9  COPY -from-dependencies /tourmix/node_modules ./node_modules
10 RUN npx prisma generate
11 RUN npm run build
12
13 FROM node:lts as runner
14 WORKDIR /tourmix
15 ENV NODE_ENV production
16 # If you are using a custom next.config.js file, uncomment this line.
17 COPY --from-builder /tourmix/next.config.js ./
18 COPY --from-builder /tourmix/public ./public 
19 COPY --from-builder /tourmix/.next ./.next
20 COPY --from-builder /tourmix/node_modules ./node_modules
21 COPY -from-builder /tourmix/package.json ./package.json
22 COPY --from-builder /tourmix/.env ./.env

24 # copy the prisma folder
25 EXPOSE 3000
26 CMD ["yarn", "start"]

This is my GitHub workflow file:

 # This is a basic workflow that is manually triggered
 name: Deploy application

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
  push:
    branches: [master]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "greet"
  deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
      # Steps represent a sequence of tasks that will be executed as part of the job
      steps:
        - name: multiple command
          uses: appleboy/ssh-action@master
          with:
            host: ${{secrets.SSH_HOST}}
            username: ${{ secrets. SSH_USER }} 
            key: ${{ secrets.SSH_PRIVATE_KEY }}
            port: ${{ secrets.SSH_PORT}} passphrase: ${{ secrets.SSH_PASSPHRASE}} 
            script:|
              docker system prune -a -f
              cd /mnt/tourmix-main
              git pull origin master --rebase
              make release
              docker system prune -a -f

          - uses: actions/checkout@v3
            with:
              clean: 'true'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do not add screenshot of text data: copy the text directly in your question. – VonC Oct 09 '22 at 10:19
  • "Do not add screenshot of text data" means: please copy the content of your GitHub workflow file, not the image. – VonC Oct 09 '22 at 11:20
  • I am sorry but there would be too much code if I would copy the workflow file into the post and stackoverflow doesn't allow it. – Matteo Robert Oct 09 '22 at 11:25
  • You do not have to copy everything, only the relevant part, as explained/illustrated in [An image of your code is not helpful](http://idownvotedbecau.se/imageofcode). And Stack Overflow allows it. I just did it for your GitHub workflow file. – VonC Oct 09 '22 at 11:33

1 Answers1

0

Start with the first error:

Add a git clean pre-step in your pipeline, to clean any private file from your workspace.

If you are using GitLab as a CICD platform, use Git clean flags (GitLab Runner 11.10+, Q2 2019)

For a GitHub Action, if the error is on the git pull command, add a git clean -ffdx just before the git pull.

            script:|
              docker system prune -a -f
              cd /mnt/tourmix-main
              git clean -ffdx                  <====
              git stash                        <====
              git pull origin master --rebase
              make release
              docker system prune -a -f
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I am using github actions. In order to add git clean to the pipeline, should I include it in the dockerfile? – Matteo Robert Oct 09 '22 at 09:37
  • @MatteoRobert If you are using a `actions/checkout@v3`, just add a `clean: true` parameter to it. – VonC Oct 09 '22 at 10:15
  • I attached my workflow file to the post. I used clean true but it still gives me the error. – Matteo Robert Oct 09 '22 at 10:41
  • @MatteoRobert I have edited my answer accordingly, but please: read [An image of your code is not helpful](http://idownvotedbecau.se/imageofcode). – VonC Oct 09 '22 at 11:24
  • I tried adding git clean -ffdx but I still get the git error. @VonC – Matteo Robert Oct 09 '22 at 11:29
  • My log: ======END====== out: Total reclaimed space: 0B out: Removing backup/ out: Removing database/ err: error: cannot pull with rebase: You have unstaged changes. err: error: please commit or stash them. out: docker build -f Dockerfile . -t tourmix-next – Matteo Robert Oct 09 '22 at 11:32
  • @MatteoRobert Yes, I have edited the answer to address that error. – VonC Oct 09 '22 at 11:33
  • I have same script in my workflow file. with: host: ${{ secrets.SSH_HOST }} username: ${{ secrets.SSH_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} port: ${{ secrets.SSH_PORT }} passphrase: ${{ secrets.SSH_PASSPHRASE }} script: | docker system prune -a -f cd /mnt/tourmix-main git clean -ffdx git pull origin master --rebase make release docker system prune -a -f – Matteo Robert Oct 09 '22 at 11:37
  • (Sorry for the terrible format of the code) – Matteo Robert Oct 09 '22 at 11:37
  • @MatteoRobert No problem. I have edited the answer to add one more possible prophylactic command. Can you check if this improves the issue? – VonC Oct 09 '22 at 11:39
  • Alright, the error went away, but unfortunately I got another one. – Matteo Robert Oct 09 '22 at 11:44
  • ======END====== out: Total reclaimed space: 0B out: Saved working directory and index state WIP on master: a2bfa53 Merge pull request #200 from tOURmix/dev err: ERROR: Repository not found. err: fatal: Could not read from remote repository. err: err: Please make sure you have the correct access rights err: and the repository exists. – Matteo Robert Oct 09 '22 at 11:44
  • I have access to the repo so I don't really understand the problem here – Matteo Robert Oct 09 '22 at 11:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248672/discussion-between-vonc-and-matteo-robert). – VonC Oct 09 '22 at 11:46