From 146a3fda7656ed1fafeb7076c82a30f7768013da Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Thu, 13 Apr 2023 15:38:30 -0600 Subject: [PATCH] Tweak Dockerfile for better caching --- .github/workflows/build-deploy.yaml | 41 +++++++++++++++-------------- Dockerfile | 6 ++++- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml index d43ff45..d3f2717 100644 --- a/.github/workflows/build-deploy.yaml +++ b/.github/workflows/build-deploy.yaml @@ -46,23 +46,24 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - # deploy: - # runs-on: ubuntu-latest - # name: Deploy to flux - # needs: build - # steps: - # - name: Check out Kubernetes repo - # uses: actions/checkout@v3 - # with: - # repository: rmitchellscott/kubernetes-apps - # token: ${{ secrets.PAT }} - # - id: short-sha - # uses: benjlevesque/short-sha@v1.2 - # - name: Replace the image tag - # env: - # TAG: ${{ steps.short-sha.outputs.sha }} - # run: yq -i e '(select(.kind=="Deployment" and .metadata.name==env(DEPLOYMENT)) | .spec.template.spec.containers.[].image) |= split(":").0 + ":" + env(TAG)' $YAMLPATH - # - name: Commit and push - # uses: stefanzweifel/git-auto-commit-action@v4 - # with: - # commit_message: Update image tag for ${{env.DEPLOYMENT}} to ${{ steps.short-sha.outputs.sha }} \ No newline at end of file + deploy: + runs-on: ubuntu-latest + name: Deploy to flux + needs: build + steps: + - name: Check out Kubernetes repo + uses: actions/checkout@v3 + with: + repository: rmitchellscott/kubernetes-apps + token: ${{ secrets.PAT }} + ref: "master" + - id: short-sha + uses: benjlevesque/short-sha@v1.2 + - name: Replace the image tag + env: + TAG: ${{ steps.short-sha.outputs.sha }} + run: yq -i e '(select(.kind=="Deployment" and .metadata.name==env(DEPLOYMENT)) | .spec.template.spec.containers.[].image) |= split(":").0 + ":" + env(TAG)' $YAMLPATH + - name: Commit and push + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update image tag for ${{env.DEPLOYMENT}} to ${{ steps.short-sha.outputs.sha }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index cde0498..0ca4098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,8 @@ FROM node:18-alpine +WORKDIR /app + +COPY package*.json . +RUN npm ci + COPY . . -RUN npm install CMD ["node", "index.js"] \ No newline at end of file