From 2dc8fccbdab9e09b0b5f01bb48985303176532cc Mon Sep 17 00:00:00 2001 From: David de Boer Date: Wed, 6 Dec 2023 21:22:48 +0100 Subject: [PATCH] ci: Deploy (#40) --- .dockerignore | 4 +++ .github/workflows/deploy.yml | 49 ++++++++++++++++++++++++++++++++++++ Dockerfile | 19 ++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..17ddeef --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.github/ +node_modules/ +build/ +output/ diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1876433 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,49 @@ +name: Build app and update Docker image + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set variables + id: vars + run: | + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "::set-output name=docker_image::ghcr.io/netwerk-digitaal-erfgoed/dataset-knowledge-graph" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} + + - name: Build and push image to registry + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ steps.vars.outputs.docker_image }}:${{ steps.vars.outputs.sha_short }} + ${{ steps.vars.outputs.docker_image }}:latest + + - uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Store DigitalOcean credentials + run: doctl kubernetes cluster kubeconfig save nde + + - name: Run + run: | + kubectl create job --from=cronjob/dataset-knowledge-graph dataset-knowledge-graph-run diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f6355ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:lts-alpine AS build +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN NODE_ENV=production npm run compile + +FROM node:lts-alpine +LABEL org.opencontainers.image.source = "https://github.com/netwerk-digitaal-erfgoed/dataset-knowledge-graph" +ENV NODE_ENV=production +WORKDIR /app/ +COPY package*.json ./ +RUN npm ci +COPY --from=build /app/build /app/build +COPY --from=build /app/queries /app/queries +RUN mkdir /app/output && \ + chown node /app/output +USER node +CMD ["npm", "start"]