Skip to content

add workflow to push to harbor #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ AUTHSCH_CLIENT_ID=<authSchClientId>
AUTHSCH_CLIENT_SECRET=<authSchClientSecret>
MAIL_SERVER_URL=<mailServer>
MAIL_API_KEY=<apikey>
MAIL_FROM_EMAIL=<email>
MAIL_QUEUE=<queueName>

# --- development example values
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/konzisite?schema=public
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Push Docker Image

on:
push:
branches:
- master
pull_request:
branches: ['master']

jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Registry
run: echo ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin ${{ secrets.DOCKER_REGISTRY_URL }}

- name: Build and Push Docker Image
run: |
docker buildx create --use
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64 --push -t ${{ secrets.DOCKER_REGISTRY_URL }}/konzisite-api:latest -f ./Dockerfile .

- name: Logout from Docker Registry
run: docker logout ${{ secrets.DOCKER_REGISTRY_URL }}
44 changes: 26 additions & 18 deletions src/mailing/mailing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ type Templates = Record<string, string> & { default: string }

interface SendMail {
to: string
from: string
from: {
name: string
email: string
}
subject: string
html: string
queue?: string
}

export interface Setup {
Expand Down Expand Up @@ -99,29 +103,33 @@ export class MailingService {
* Sends a mail through the mailing delivery service provided in the setup process.
* @param {SendMail[]} data - Array of objects containing to, from, subject and html string fields.
*/
sendMail(data: SendMail[]) {
async sendMail(data: SendMail[]) {
MailingService.checkSetup()
if (process.env.NODE_ENV !== 'production') {
this.logger.debug(
`The app would be sending ${data.length} email(s) right now, but email sending is only enabled in production.`,
)
return Promise.resolve(false)
}
return axios
.post(MailingService.mailServerUrl, data, {
headers: { 'X-Api-Key': MailingService.apiKey },
})
.then(() => {
this.logger.log(
`${data.length} email data sent to Kir-Dev email service`,
)
return true
})
.catch((e) => {
this.logger.log('Error during email sending')
this.logger.error(e)
return false
})
try {
await Promise.all(
data.map((email) =>
axios.post(
MailingService.mailServerUrl,
{ ...email, queue: process.env.MAIL_QUEUE },
{
headers: { Authorization: `Api-Key ${MailingService.apiKey}` },
},
),
),
)
this.logger.log(`${data.length} email data sent to Kir-Dev email service`)
return true
} catch (e) {
this.logger.log('Error during email sending')
this.logger.error(e)
return false
}
}

private static checkSetup() {
Expand Down Expand Up @@ -172,7 +180,7 @@ export class MailingService {
consultationUrl: `${process.env.FRONTEND_HOST}/consultations/${consultation.id}`,
})
return {
from: 'Konzisite',
from: { name: 'Konzisite', email: process.env.MAIL_FROM_EMAIL },
to: u.email,
subject: 'Megvalósul egy konzi kérésed!',
html,
Expand Down
Loading