Skip to content

Commit bcdce37

Browse files
committed
Use GitHub actions to deploy to DockerHub
1 parent fbf2d7f commit bcdce37

2 files changed

Lines changed: 100 additions & 54 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: CI and Multi-Arch Docker Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
cache: npm
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Run lint
30+
run: npm run lint
31+
32+
test:
33+
runs-on: ubuntu-latest
34+
needs: [lint]
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- name: Set up Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: 20
43+
cache: npm
44+
45+
- name: Install dependencies
46+
run: npm ci
47+
48+
- name: Run tests
49+
run: npm test
50+
51+
build:
52+
runs-on: ubuntu-latest
53+
needs: [test]
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v4
57+
58+
- name: Set up Node.js
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: 20
62+
cache: npm
63+
64+
- name: Install dependencies
65+
run: npm ci
66+
67+
- name: Build project
68+
run: npx tsc
69+
70+
- name: Upload dist artifact
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: prod-assets
74+
path: dist/
75+
76+
build-and-deploy:
77+
runs-on: ubuntu-latest
78+
needs: [lint, test, build]
79+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
80+
steps:
81+
- name: Checkout repository
82+
uses: actions/checkout@v4
83+
- name: Download dist artifact
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: prod-assets
87+
path: dist/
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v3
90+
- name: Log in to Docker Container Registry
91+
uses: docker/login-action@v3
92+
with:
93+
username: ${{ secrets.DOCKER_USERNAME }}
94+
password: ${{ secrets.DOCKER_PASSWORD }}
95+
- name: Build and push multi-arch Docker image
96+
run: |
97+
docker buildx build \
98+
--platform linux/amd64,linux/arm64 \
99+
--tag ${{ vars.DOCKER_IMAGE_NAME }}:latest . \
100+
--push

.gitlab-ci.yml

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ cache:
1212
stages:
1313
- code-analysis
1414
- test
15-
- deploy:images
16-
- deploy:retagging
1715

1816
workflow:
1917
rules:
@@ -38,55 +36,3 @@ test:
3836
script:
3937
- npm install
4038
- npm run test
41-
42-
.deploy-to-dockerhub:
43-
stage: deploy:images
44-
tags:
45-
- exec-docker
46-
variables:
47-
DOCKERHUB_TAG: "latest"
48-
image:
49-
name: gcr.io/kaniko-project/executor:debug
50-
entrypoint: [""]
51-
script:
52-
- mkdir -p /kaniko/.docker
53-
- echo "{\"auths\":{\"$CONTAINER_REGISTRY_URL\":{\"auth\":\"$(echo -n ${DOCKERHUB_USERNAME}:${DOCKERHUB_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
54-
- /kaniko/executor
55-
--context=$CI_PROJECT_DIR
56-
--dockerfile=$CI_PROJECT_DIR/Dockerfile
57-
--destination=$DOCKERHUB_ORGANIZATION/$DOCKERHUB_IMAGE_NAME:$DOCKERHUB_TAG
58-
59-
deploy-backend-amd64:
60-
variables:
61-
DOCKERHUB_TAG: "amd64"
62-
extends:
63-
- .deploy-to-dockerhub
64-
rules:
65-
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
66-
- if: $CI_PIPELINE_SOURCE == "schedule"
67-
- if: $CI_PIPELINE_SOURCE == "web"
68-
69-
deploy-backend-arm64:
70-
variables:
71-
DOCKERHUB_TAG: "arm64"
72-
extends:
73-
- .deploy-to-dockerhub
74-
tags:
75-
- arm64
76-
rules:
77-
- if: $CI_PIPELINE_SOURCE == "schedule"
78-
- if: $CI_PIPELINE_SOURCE == "web"
79-
80-
retag-backend-as-latest:
81-
extends: .retag-dockerhub-image
82-
rules:
83-
- if: $CI_PIPELINE_SOURCE == "web" || $CI_PIPELINE_SOURCE == "schedule"
84-
when: never
85-
variables:
86-
SOURCE_TAG: "amd64"
87-
TARGET_TAG: "latest"
88-
89-
publish-multi-arch-backend:
90-
extends: .retag-as-multi-arch-dockerhub-image
91-
variables:
92-
MANIFEST_PLATFORMS: "linux/amd64,linux/arm64/v8"

0 commit comments

Comments
 (0)