|
| 1 | +name: Bygg, publish og deploy |
| 2 | +on: push |
| 3 | +env: |
| 4 | + APP: sykepengesoknad |
| 5 | +jobs: |
| 6 | + build-and-publish: |
| 7 | + name: Bygg, test og push Docker image |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Checkout code |
| 11 | + uses: actions/checkout@v1 |
| 12 | + - name: Generer versjon og image navn |
| 13 | + run: | |
| 14 | + TIME=$(TZ="Europe/Oslo" date +%Y.%m.%d-%H.%M) |
| 15 | + COMMIT=$(git rev-parse --short=8 HEAD) |
| 16 | + VERSION=$TIME-$COMMIT |
| 17 | + echo "::set-env name=IMAGE::"docker.pkg.github.com/${GITHUB_REPOSITORY}/$APP:$VERSION"" |
| 18 | + echo "::set-env name=VERSION::"$VERSION"" |
| 19 | + - run: echo $VERSION > VERSION.txt |
| 20 | + - name: Last opp VERSION til neste job |
| 21 | + uses: actions/upload-artifact@v1 |
| 22 | + with: |
| 23 | + name: VERSION.txt |
| 24 | + path: VERSION.txt |
| 25 | + - name: Cache NPM dependencies |
| 26 | + uses: actions/cache@v1 |
| 27 | + with: |
| 28 | + path: node_modules |
| 29 | + key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }} |
| 30 | + restore-keys: | |
| 31 | + ${{ runner.OS }}-npm-cache- |
| 32 | + - name: Install npm dependencies |
| 33 | + run: npm i |
| 34 | + - name: Run lint |
| 35 | + run: npm run lint |
| 36 | + - name: Run tests |
| 37 | + run: npm run test |
| 38 | + - name: Build application |
| 39 | + run: npm run nais-build |
| 40 | + - name: Build and publish Docker image |
| 41 | + env: |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} |
| 43 | + run: | |
| 44 | + docker build -t ${IMAGE} . |
| 45 | + docker login docker.pkg.github.com -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN} |
| 46 | + docker push ${IMAGE} |
| 47 | +
|
| 48 | + deploy-to-dev-sbs: |
| 49 | + name: Deploy til dev-sbs (Q1) |
| 50 | + runs-on: ubuntu-latest |
| 51 | + needs: build-and-publish |
| 52 | + steps: |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v1 |
| 55 | + - name: Last ned versjon |
| 56 | + uses: actions/download-artifact@v1 |
| 57 | + with: |
| 58 | + name: VERSION.txt |
| 59 | + path: . |
| 60 | + - run: echo "::set-env name=VERSION::"`cat VERSION.txt`"" |
| 61 | + - run: echo "::set-env name=IMAGE::"docker.pkg.github.com/${GITHUB_REPOSITORY}/$APP:$VERSION"" |
| 62 | + - uses: nais/deploy/actions/deploy@v1 |
| 63 | + name: Deploy to dev-sbs |
| 64 | + env: |
| 65 | + APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} |
| 66 | + CLUSTER: dev-sbs |
| 67 | + RESOURCE: nais-dev.yaml |
| 68 | + |
| 69 | + deploy-to-prod-sbs: |
| 70 | + if: github.ref == 'refs/heads/master' |
| 71 | + name: Deploy til prod-sbs (Produksjon) |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: build-and-publish |
| 74 | + steps: |
| 75 | + - name: Checkout code |
| 76 | + uses: actions/checkout@v1 |
| 77 | + - name: Last ned versjon |
| 78 | + uses: actions/download-artifact@v1 |
| 79 | + with: |
| 80 | + name: VERSION.txt |
| 81 | + path: . |
| 82 | + - run: echo "::set-env name=VERSION::"`cat VERSION.txt`"" |
| 83 | + - run: echo "::set-env name=IMAGE::"docker.pkg.github.com/${GITHUB_REPOSITORY}/$APP:$VERSION"" |
| 84 | + - uses: nais/deploy/actions/deploy@v1 |
| 85 | + name: Deploy to prod-sbs |
| 86 | + env: |
| 87 | + APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} |
| 88 | + CLUSTER: prod-sbs |
| 89 | + RESOURCE: nais-prod.yaml |
| 90 | + - uses: actions/create-release@v1 |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + with: |
| 94 | + tag_name: ${{ env.VERSION }} |
| 95 | + release_name: ${{ env.VERSION }} |
0 commit comments