Skip to content

Commit

Permalink
Update GitHub Actions workflow and Docker image build process
Browse files Browse the repository at this point in the history
  • Loading branch information
sofusalbertsen committed Jan 23, 2024
1 parent e147744 commit 344d675
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Main workflow
on: push
env: # Set the secret as an input
docker_username: ${{ github.actor }}
docker_password: ${{ secrets.GITHUB_TOKEN }}
GIT_COMMIT: ${{ github.sha }}
jobs:
Build:
runs-on: ubuntu-latest
Expand All @@ -10,4 +14,19 @@ jobs:
- name: Build application
run: ci/build-app.sh
- name: Test
run: ci/unit-test-app.sh
run: ci/unit-test-app.sh
Docker-image:
runs-on: ubuntu-latest
needs: [Build]
permissions:
packages: write
steps:
- name: Download code
uses: actions/download-artifact@v3
with:
name: code
path: .
- name: build docker
run: ci/build-docker.sh
- name: push docker
run: ci/push-docker.sh
17 changes: 6 additions & 11 deletions labs/docker-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ If you strugle and need to see the whole ***Solution*** you can extend the secti
<summary> Solution </summary>

```YAML
name: Hello world workflow
name: Main workflow
on: push
env: # Set the secret as an input
docker_username: ${{ github.actor }}
Expand All @@ -149,17 +149,12 @@ jobs:
runs-on: ubuntu-latest
container: gradle:6-jdk11
steps:
- name: Clone-down
- name: Clone down repository
uses: actions/checkout@v4
- name: Build application
run: chmod +x ci/build-app.sh && ci/build-app.sh
run: ci/build-app.sh
- name: Test
run: chmod +x ci/unit-test-app.sh && ci/unit-test-app.sh
- name: Upload Repo
uses: actions/upload-artifact@v3
with:
name: code
path: .
run: ci/unit-test-app.sh
Docker-image:
runs-on: ubuntu-latest
needs: [Build]
Expand All @@ -172,9 +167,9 @@ jobs:
name: code
path: .
- name: build docker
run: chmod +x ci/build-docker.sh && ci/build-docker.sh
run: ci/build-docker.sh
- name: push docker
run: chmod +x ci/push-docker.sh && ci/push-docker.sh
run: ci/push-docker.sh
```

</details>
Expand Down
27 changes: 11 additions & 16 deletions labs/storing-artifacts.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
## Storing artifacts

When running multiple jobs, the VM you get for each job is completely new.
When running multiple jobs, the runner you get for each job is completely new.

This means that the state of the repository is not persisted between jobs.

It is possible to store your state (and therfore also artifacts) in Github Actions.

An `artifact` could be the result of the build, in this case the compiled code.

> This should not be mistaken for proper [artifact management](https://www.eficode.com/blog/artifactory-nexus-proget), or [release management](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) but it is useful for making the artifacts built by the pipeline available.
> :bulb: This should not be mistaken for proper [artifact management](https://www.eficode.com/blog/artifactory-nexus-proget), or [release management](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) but it is useful for making the artifacts built by the pipeline available.
To deal with artifacts, a `Github Actions Action` can be used, which can be found on [Github Marketplace](https://github.com/marketplace).

To upload artifacts use the following syntax with `actions/upload-artifact@v3` [Link to documentation](https://github.com/marketplace/actions/upload-a-build-artifact):
To upload artifacts use the following syntax with `actions/upload-artifact@v4` [Link to documentation](https://github.com/marketplace/actions/upload-a-build-artifact):

```YAML
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: my-artifact
path: path/to/artifact/
```
As artifacts can be uploaded it can also be downloaded from Github Actions with help of `actions/download-artifact@v3` as:
As artifacts can be uploaded it can also be downloaded from Github Actions with help of `actions/download-artifact@v4` as:

```YAML
- name: Download a single artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: my-artifact
path: path/to/download/artifact/
```

[Link to documentation](https://github.com/actions/download-artifact)

This information will be needed in next exercises.

:bulb:
<details>
<summary> More information about storing artifacts </summary>
Expand Down Expand Up @@ -69,20 +63,21 @@ If you strugle and need to see the whole ***Solution*** you can extend the secti
<summary> Solution </summary>

```YAML
name: Main workflow
on: push
jobs:
Build:
runs-on: ubuntu-latest
container: gradle:6-jdk11
steps:
- name: Clone-down
- name: Clone down repository
uses: actions/checkout@v4
- name: Build application
run: chmod +x ci/build-app.sh && ci/build-app.sh
run: ci/build-app.sh
- name: Test
run: chmod +x ci/unit-test-app.sh && ci/unit-test-app.sh
run: ci/unit-test-app.sh
- name: Upload Repo
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: code
path: .
Expand Down

0 comments on commit 344d675

Please sign in to comment.