Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: combining skaffold with Github Actions #4811

Closed
NixBiks opened this issue Sep 21, 2020 · 7 comments
Closed

Question: combining skaffold with Github Actions #4811

NixBiks opened this issue Sep 21, 2020 · 7 comments
Labels
kind/question User question

Comments

@NixBiks
Copy link

NixBiks commented Sep 21, 2020

I have a project where I run skaffold locally to build and deploy. That works perfectly fine but I want to integrate it with Github Actions so I can build and deploy on pushes. My current approach is

  1. Checkout the repo
  2. Install gcloud, kustomize, kubectl and skaffold
  3. Authenticate gcloud and configure-docker
  4. Connect to GKE cluster
  5. Build and deploy with skaffold run
name: Deployment
on: 
  push:
    branches:
      - staging
env:
  PROJECT_ID: ${{ secrets.STAGING_PROJECT }}
  GKE_CLUSTER: my-cluster
  GKE_ZONE: europe-west3-a
  SKAFFOLD_DEFAULT_REPO: gcr.io/${{ secrets.STAGING_PROJECT }}/parallax
  SKAFFOLD_PROFILE: staging

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Install gcloud
        uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
        with:
          version: '309.0.0'
          service_account_key: ${{ secrets.STAGING_SA_BUILD_AND_DEPLOY }}
          project_id: ${{ secrets.STAGING_PROJECT }}
      - name: Install kustomize, kubectl and skaffold
        uses: daisaru11/setup-cd-tools@v1
        with:
          kubectl: '1.19.2'
          kustomize: '3.8.4'
          skaffold: '1.14.0'
      - name: Configure docker
        run: |
          gcloud --quiet auth configure-docker
      - name: Connect to cluster
        run: |
          gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
      - name: Set default repo for Skaffold
        run: |
          skaffold config set default-repo "$SKAFFOLD_DEFAULT_REPO"
      - name: Build and deploy to cluster
        run: |
          skaffold run \
          --profile "$SKAFFOLD_PROFILE" \
          -l skaffold.dev/run-id=LEAVE_UNCHANGED

I have a number of issues though

  1. The last deployment step fails: Error from server (NotFound): the server could not find the requested resource
  2. All containers are rebuilt - also the ones that hasn't changed (I have a mono repo with several services that are being built). I'd expect skaffold to notice this from the remote repo cache?
  3. The containers are not built in parallel - I was thinking using Cloud Build to overcome this but then I run into authentication issues.

I'm thinking this is somewhat common task so I expect there'll be some best practices to lean towards?

Information

  • Skaffold version: 1.14.0
  • Operating system: ubuntu
  • Contents of skaffold.yaml:
apiVersion: skaffold/v1beta15
kind: Config
build:
  tagPolicy:
    sha256: {}
  artifacts:
    - image: python-backend
      context: .
      docker:
        dockerfile: services/backend/Dockerfile
      sync:
        manual:
          - src: "services/backend/**"
            dest: ./
            strip: "services/backend"
          - src: "**/.coverage"
            dest: ./
          - src: "**/.pytest_cache/**"
            dest: ./
          - src: "**/.history/**"
            dest: ./
          - src: "lib/**"
            dest: /opt/lib
            strip: "lib"
    - image: pdf-worker
      context: .
      docker:
        dockerfile: services/pdfs/Dockerfile
      sync:
        manual:
          - src: "services/pdfs/**"
            dest: ./
            strip: "services/pdfs"
          - src: "**/.coverage"
            dest: ./
          - src: "**/.pytest_cache/**"
            dest: ./
          - src: "**/.history/**"
            dest: ./
          - src: "lib/**"
            dest: /opt/lib
            strip: "lib"
    - image: old-alba-worker
      context: .
      docker:
        dockerfile: services/alba/Dockerfile
      sync:
        manual:
          - src: "services/alba/**"
            dest: .
            strip: "services/alba"
          - src: "**/.coverage"
            dest: ./
          - src: "**/.pytest_cache/**"
            dest: ./
          - src: "**/.history/**"
            dest: ./
          - src: "lib/**"
            dest: /opt/lib
            strip: "lib"
    - image: react-frontend
      context: services/frontend
      sync:
        manual:
          - src: "src/**"
            dest: .

profiles:
  - name: staging
    deploy:
      kustomize:
        path: k8s-manifest/staging
  - name: production
    deploy:
      kustomize:
        path: k8s-manifest/production
  - name: local
    deploy:
      kustomize:
        path: k8s-manifest/local
    # activate if the kube context is minikube
    activation:
      - kubeContext: minikube
    patches:
      # target 'development' in all dockerfiles (and test the order of artifacts is the same, e.g. react-frontend is handled differently)
      - op: test
        path: /build/artifacts/0/image
        value: python-backend
      - op: add
        path: /build/artifacts/0/docker/target
        value: development
      - op: test
        path: /build/artifacts/1/image
        value: pdf-worker
      - op: add
        path: /build/artifacts/1/docker/target
        value: development
      - op: test
        path: /build/artifacts/2/image
        value: old-alba-worker
      - op: add
        path: /build/artifacts/2/docker/target
        value: development
      - op: test
        path: /build/artifacts/3/image
        value: react-frontend
      - op: add
        path: /build/artifacts/3/docker
        value: {target: development}
@NixBiks
Copy link
Author

NixBiks commented Sep 21, 2020

Revisit

  1. Turns out I had typo on the kubectl version when pinning it which caused the issue
  2. Waiting for help
  3. Waiting for help

@NixBiks
Copy link
Author

NixBiks commented Sep 21, 2020

I expect this to be related to my bullet point number 2.

@MarlonGamez MarlonGamez added the kind/question User question label Sep 21, 2020
@MarlonGamez
Copy link
Contributor

Hi @mr-bjerre, thanks for opening this issue :) For building in parallel, I believe you have to manually enable that in your skaffold.yaml by updating the field build.local.concurrency. There's some more info on that here under the "Faster Builds" section of "Local Build"

@NixBiks
Copy link
Author

NixBiks commented Sep 21, 2020

I tried that but for some reason I'm not allowed to give that. I'm getting the following error

parsing skaffold config: unable to parse config: yaml: unmarshal errors:
  line 51: field concurrency not found in type v1beta15.LocalBuild

This is what I have

build:
  local:
    concurrency: 0

@MarlonGamez
Copy link
Contributor

Ah, it looks like that field wasn't added until skaffold schema v2alpha2. If you want to update your schema to a later version you can use skaffold fix. This will print an updated schema to stdout and won't actually override your skaffold.yaml unless you run with --overwrite=true

@NixBiks
Copy link
Author

NixBiks commented Sep 21, 2020

Ah I see thanks 🙏

Also; do you by any chance have any idea on my second question (that’s the real killer)?

@NixBiks
Copy link
Author

NixBiks commented Oct 1, 2020

Closing in favour of #4842

@NixBiks NixBiks closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question User question
Projects
None yet
Development

No branches or pull requests

2 participants