title | author |
---|---|
Continuous integration using GitHub Actions |
Part 2 of 3 in the [Build end-to-end CI/CD capabilities directly in GitHub](https://github.com/MSUSDEV/end-to-end-github-actions) series |
Presenter Name
☁️ Presenter Title
For questions or help with this series: [email protected]
All demos and source code available online:
Session 1:Introduction to GitHub Actions
- Session 2:
- ↪️ Continuous integration using GitHub Actions
- Session 3:
- Deploy applications to Azure using GitHub Actions
- Exploring a sample Next.js web application
- Building and validating the project
- Creating a GitHub release
- Docker-izing the project
- Automating Docker container builds
::: notes
-
Get the web project (https://github.com/msusdev/example-next-web-app)
-
Build and validate web project
npm install npm install --global next
-
Create build job in workflow
name: Build Next.js web application on: push jobs: build-project: name: Build Project runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install NPM dependencies run: npm install - name: Build project assets run: npm run build
-
Upload artifact
- name: Upload static site uses: actions/upload-artifact@v2 with: name: static-site path: .next/
-
Create release job
release-project: name: Release Project runs-on: ubuntu-latest needs: build-project
-
Download artifact
- name: Download site content uses: actions/download-artifact@v2 with: name: site-build
-
View contents of downloaded artifact
- name: View content run: ls -R
-
Create GitHub release
- name: Create GitHub release id: create-new-release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.run_number }} release_name: Release ${{ github.run_number }}
-
Compress folder
- name: Archive site content uses: thedoctor0/zip-release@master with: filename: site.zip
-
Upload asset to release
- name: Upload release asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create-new-release.outputs.upload_url }} asset_path: ./site.zip asset_name: site-v${{ github.run_number }}.zip asset_content_type: application/zip
-
Create Dockerfile
FROM node:alpine WORKDIR /app COPY . /app RUN npm install RUN npm run build EXPOSE 80 CMD npm run start
-
Test container locally
docker build --tag next . docker run --detach --publish 5000:3000 next
-
Add container job
name: Build container runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2
-
Push to Docker Hub
- name: Push to Docker Hub uses: docker/build-push-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: msusdev/webnext tags: latest, ${{ github.run_number }}
-
Test Docker Hub locally
docker pull msusdev/webnext docker run --detach --publish 4000:3000 msusdev/webnext:latest
-
Push to GitHub Packages
- name: Publish to GitHub Packages uses: docker/build-push-action@v1 with: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: docker.pkg.github.com repository: ${{ github.repository }}/webnext tags: latest, ${{ github.run_number }}
-
Test GitHub Packages locally
docker login https://docker.pkg.github.com docker pull docker.pkg.github.com/msusdev/preshow-test/webnext docker run --detach --publish 2000:3000 docker.pkg.github.com/msusdev/preshow-test/webnext
-
Final results https://github.com/msusdev/example-next-web-app
:::
- Exploring a sample Next.js web application
- Building and validating the project
- Creating a GitHub release
- Docker-izing the project
- Automating Docker container builds
- https://github.com/actions/upload-artifact
- https://github.com/actions/download-artifact
- https://docs.github.com/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds
- https://github.com/actions/create-release
- https://docs.github.com/actions/reference/context-and-expression-syntax-for-github-actions#contexts
- https://github.com/marketplace/actions/zip-release
- https://github.com/actions/upload-release-asset
- https://docs.github.com/actions/guides/publishing-docker-images
- https://github.com/docker/build-push-action/tree/releases/v1
https://lab.github.com/msusdev/build-end-to-end-cicd-capabilities-directly-in-github