Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Latest commit

 

History

History
113 lines (97 loc) · 2.99 KB

01.1_Docker-Workflow.md

File metadata and controls

113 lines (97 loc) · 2.99 KB

Edit the workflow file

Step 2: Edit the workflow file

We are going to edit the current workflow file in our repository by adding a job that turns our Dockerfile into a Docker Image.

⌨️ Activity: Edit the workflow file and turn the Dockerfile into a Docker Image

  1. [Edit the current workflow file in our repository]({{ repoUrl }}/blob/docker-workflow/.github/workflows/ci-workflow.yml)
  2. Rename ci-workflow.yml to cd-workflow.yml:
  3. On line 1, change the name from Node CI to Docker CD yaml name: Docker CD
  4. Add the following job to your workflow file:
  Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: test
    name: Docker Build, Tag, Push

    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Download built artifact
      uses: actions/download-artifact@main
      with:
        name: webpack artifacts
        path: public
    - name: Build container image
      uses: docker/build-push-action@v1
      with:
        username: {% raw %}${{github.actor}}{% endraw %}
        password: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
        registry: docker.pkg.github.com
        repository: {{ user.login }}/github-actions-for-packages/tic-tac-toe
        tag_with_sha: true
  1. Commit the newly edited workflow file to your repository
Complete cd-workflow.yml file...
name: Docker CD

on:
  push:
    paths:
    - "**Dockerfile**"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: npm install and build webpack
      run: |
        npm install
        npm run build
    - uses: actions/upload-artifact@main
      with:
        name: webpack artifacts
        path: public/

  test:
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        os: [ubuntu-lastest, windows-2016]
        node-version: [12.x, 14.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js {% raw %}${{ matrix.node-version }}{% endraw %}
      uses: actions/setup-node@v1
      with:
        node-version: {% raw %}${{ matrix.node-version }}{% endraw %}
    - uses: actions/download-artifact@main
      with:
        name: webpack artifacts
        path: public
    - name: npm install, and test
      run: |
        npm install
        npm test
      env:
        CI: true

  Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: test
    name: Docker Build, Tag, Push

    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Download built artifact
      uses: actions/download-artifact@main
      with:
        name: webpack artifacts
        path: public
    - name: Build container image
      uses: docker/build-push-action@v1
      with:
        username: {% raw %}${{github.actor}}{% endraw %}
        password: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
        registry: docker.pkg.github.com
        repository: {{ user.login }}/github-actions-for-packages/tic-tac-toe
        tag_with_sha: true