-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (69 loc) · 2.04 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Build and Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
IMAGE_NAME: ghcr.io/${{ github.repository }}:latest
IMAGE_PATH: image.tar
jobs:
# compilation job
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# build the project
- name: Build the project
run: cargo build --release --verbose
# upload neccesary build files as an artifact
- name: Archive build artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
target/release/sport-challenge
# building the image job
container_build:
# only run on main branch and not other branches/ pull-requests
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
# download the previously created build artifact
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
path: target/release/
# building the docker image
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME
docker save $IMAGE_NAME > image.tar
# upload the docker image as an artifact
- name: Archive container artifacts
uses: actions/upload-artifact@v3
with:
name: container-image-artifact
path: image.tar
# deploying the image job
container_deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: container_build
steps:
- uses: actions/checkout@v3
# download the previously created docker image
- name: Download container artifact
uses: actions/download-artifact@v3
with:
name: container-image-artifact
# publish the image to GitHub packages
- name: Publish the image
run: |
docker load < image.tar
docker login --username ${{ github.repository_owner }} --password ${{ secrets.GH_PAT }} ghcr.io
docker push $IMAGE_NAME